workOrderListUserContext.test.mjs
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildWorkOrderListUserContext,
passesWorkOrderAccountGate
} from '../pages/tabWorkOrder/pages/index/index.helpers.js'
describe('work order list user context', () => {
it('keeps merchant access outside userInfo when onShow rewrites the raw user object', () => {
const rawUserInfo = {
merchantAccountList: ['6'],
loginRole: 4,
userType: 2
}
const context = buildWorkOrderListUserContext(rawUserInfo)
assert.equal(context.merchantType, true)
assert.equal(context.isMake, true)
assert.equal(
passesWorkOrderAccountGate({
userInfo: rawUserInfo,
merchantType: context.merchantType,
isMake: context.isMake
}),
true
)
})
it('accepts numeric merchant account types returned by different login paths', () => {
const context = buildWorkOrderListUserContext({
merchantAccountList: [8],
loginRole: 4,
userType: 2
})
assert.equal(context.merchantType, true)
})
it('still blocks super administrators and multi-store roles', () => {
const superContext = buildWorkOrderListUserContext({
merchantAccountList: ['6'],
isSuper: true,
userType: 2
})
const salesContext = buildWorkOrderListUserContext({
merchantAccountList: ['6'],
loginRole: 5,
userType: 2
})
assert.equal(passesWorkOrderAccountGate(superContext), false)
assert.equal(salesContext.isMake, false)
assert.equal(passesWorkOrderAccountGate(salesContext), false)
})
})