-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathuse-self-custodial-rollback.spec.ts
More file actions
118 lines (92 loc) · 3.09 KB
/
Copy pathuse-self-custodial-rollback.spec.ts
File metadata and controls
118 lines (92 loc) · 3.09 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { renderHook } from "@testing-library/react-native"
import { AccountStatus, AccountType } from "@app/types/wallet.types"
import { useSelfCustodialRollback } from "@app/hooks/use-self-custodial-rollback"
let mockNonCustodialEnabled = true
jest.mock("@app/config/feature-flags-context", () => ({
useFeatureFlags: () => ({
nonCustodialEnabled: mockNonCustodialEnabled,
}),
}))
const custodialAccount = {
id: "custodial-default",
type: AccountType.Custodial,
label: "Custodial",
selected: false,
status: AccountStatus.Available,
}
const selfCustodialAccount = {
id: "sc-default",
type: AccountType.SelfCustodial,
label: "Self-custodial",
selected: true,
status: AccountStatus.Available,
}
describe("useSelfCustodialRollback", () => {
const mockSetActiveAccountId = jest.fn()
beforeEach(() => {
jest.clearAllMocks()
mockNonCustodialEnabled = true
})
it("rolls back when flag disabled and active is self-custodial", () => {
mockNonCustodialEnabled = false
renderHook(() =>
useSelfCustodialRollback({
activeAccount: selfCustodialAccount,
accounts: [custodialAccount, selfCustodialAccount],
setActiveAccountId: mockSetActiveAccountId,
}),
)
expect(mockSetActiveAccountId).toHaveBeenCalledWith("custodial-default")
})
it("does not roll back when flag is enabled", () => {
mockNonCustodialEnabled = true
renderHook(() =>
useSelfCustodialRollback({
activeAccount: selfCustodialAccount,
accounts: [custodialAccount, selfCustodialAccount],
setActiveAccountId: mockSetActiveAccountId,
}),
)
expect(mockSetActiveAccountId).not.toHaveBeenCalled()
})
it("does not roll back when active account is custodial", () => {
mockNonCustodialEnabled = false
renderHook(() =>
useSelfCustodialRollback({
activeAccount: custodialAccount,
accounts: [custodialAccount],
setActiveAccountId: mockSetActiveAccountId,
}),
)
expect(mockSetActiveAccountId).not.toHaveBeenCalled()
})
it("does not roll back when no custodial fallback exists", () => {
mockNonCustodialEnabled = false
renderHook(() =>
useSelfCustodialRollback({
activeAccount: selfCustodialAccount,
accounts: [selfCustodialAccount],
setActiveAccountId: mockSetActiveAccountId,
}),
)
expect(mockSetActiveAccountId).not.toHaveBeenCalled()
})
it("re-fires rollback on off→on→off flag toggle", () => {
mockNonCustodialEnabled = false
const { rerender } = renderHook(() =>
useSelfCustodialRollback({
activeAccount: selfCustodialAccount,
accounts: [custodialAccount, selfCustodialAccount],
setActiveAccountId: mockSetActiveAccountId,
}),
)
expect(mockSetActiveAccountId).toHaveBeenCalledTimes(1)
mockSetActiveAccountId.mockClear()
mockNonCustodialEnabled = true
rerender({})
expect(mockSetActiveAccountId).not.toHaveBeenCalled()
mockNonCustodialEnabled = false
rerender({})
expect(mockSetActiveAccountId).toHaveBeenCalledWith("custodial-default")
})
})