login changes
This commit is contained in:
65
src/features/onboarding/shouldOfferSetup.test.ts
Normal file
65
src/features/onboarding/shouldOfferSetup.test.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import { test } from 'node:test';
|
||||
import { EMPTY_DELIVERY, EMPTY_STORE, type OnboardingState } from './onboardingState';
|
||||
import { shouldOfferSetup } from './shouldOfferSetup';
|
||||
|
||||
const FRESH: OnboardingState = {
|
||||
step: 'welcome',
|
||||
completed: [],
|
||||
skipped: [],
|
||||
finished: false,
|
||||
started: false,
|
||||
store: EMPTY_STORE,
|
||||
delivery: EMPTY_DELIVERY,
|
||||
};
|
||||
|
||||
const at = (over: Partial<Parameters<typeof shouldOfferSetup>[0]> = {}) =>
|
||||
shouldOfferSetup({
|
||||
pathname: '/admin/console',
|
||||
isReady: true,
|
||||
productCount: 0,
|
||||
state: FRESH,
|
||||
...over,
|
||||
});
|
||||
|
||||
test('a brand-new store admin is sent to setup on first login', () => {
|
||||
// The reported bug, and it survived a day of testing because the old rule
|
||||
// asked whether the shop had a name, address and phone — which
|
||||
// `createtenantuser` fills in at creation, so it was true of every new
|
||||
// tenant and the redirect never fired once.
|
||||
assert.equal(at(), true);
|
||||
});
|
||||
|
||||
test('a shop whose profile Nearle Admin already filled in is STILL offered setup', () => {
|
||||
// Tenants 1150, 1148 and 1146 were all newly created and all carried a name,
|
||||
// an address and a phone number. A complete profile is evidence about who
|
||||
// created the tenant, not about whether the merchant has been onboarded.
|
||||
assert.equal(at({ productCount: 0 }), true);
|
||||
});
|
||||
|
||||
test('a trading shop is never interrupted', () => {
|
||||
// R mart, 24 products. Stock on the shelf means somebody is working.
|
||||
assert.equal(at({ productCount: 24 }), false);
|
||||
});
|
||||
|
||||
test('the offer is made once, so declining it is possible', () => {
|
||||
// Without this the merchant is trapped: the welcome screen offers no way out,
|
||||
// so clicking Console to leave lands on `/admin/console` and bounces back.
|
||||
assert.equal(at({ state: { ...FRESH, started: true } }), false);
|
||||
});
|
||||
|
||||
test('somebody who finished setup is not sent through it again', () => {
|
||||
assert.equal(at({ state: { ...FRESH, finished: true } }), false);
|
||||
});
|
||||
|
||||
test('nobody is hauled away from the page they opened', () => {
|
||||
for (const pathname of ['/admin/sales', '/admin/inventory', '/admin/reports']) {
|
||||
assert.equal(at({ pathname }), false, pathname);
|
||||
}
|
||||
});
|
||||
|
||||
test('no decision is taken while the shop and its products are still loading', () => {
|
||||
// An empty product list mid-flight looks exactly like a shop with no stock,
|
||||
// which would redirect every established merchant on their first paint.
|
||||
assert.equal(at({ isReady: false }), false);
|
||||
});
|
||||
Reference in New Issue
Block a user