Skip to content

Commit a4d2614

Browse files
committed
#RI-4936 - fix tests
1 parent de4c631 commit a4d2614

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

redisinsight/ui/src/components/oauth/oauth-jobs/OAuthJobs.spec.tsx

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { addErrorNotification, addInfiniteNotification, removeInfiniteNotificati
99
import { RootState } from 'uiSrc/slices/store'
1010
import { loadInstances } from 'uiSrc/slices/instances/instances'
1111
import { INFINITE_MESSAGES, InfiniteMessagesIds } from 'uiSrc/components/notifications/components'
12+
import { CustomErrorCodes } from 'uiSrc/constants'
1213
import OAuthJobs from './OAuthJobs'
1314

1415
jest.mock('react-redux', () => ({
@@ -128,8 +129,68 @@ describe('OAuthJobs', () => {
128129
rerender(<OAuthJobs />)
129130

130131
const expectedActions = [
131-
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
132132
addErrorNotification({ response: { data: error } } as AxiosError),
133+
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
134+
]
135+
expect(clearStoreActions(store.getActions())).toEqual(
136+
clearStoreActions(expectedActions)
137+
)
138+
})
139+
140+
it('should call addInfiniteNotification and removeInfiniteNotification when errorCode is 11_108', async () => {
141+
const mockDatabaseId = '123'
142+
const error = {
143+
errorCode: CustomErrorCodes.CloudDatabaseAlreadyExistsFree,
144+
resource: {
145+
databaseId: mockDatabaseId
146+
}
147+
};
148+
(oauthCloudJobSelector as jest.Mock).mockImplementation(() => ({
149+
status: ''
150+
}))
151+
152+
const { rerender } = render(<OAuthJobs />);
153+
154+
(oauthCloudJobSelector as jest.Mock).mockImplementation(() => ({
155+
status: CloudJobStatus.Failed,
156+
error,
157+
}))
158+
159+
rerender(<OAuthJobs />)
160+
161+
const expectedActions = [
162+
addInfiniteNotification(INFINITE_MESSAGES.DATABASE_EXISTS()),
163+
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
164+
]
165+
expect(clearStoreActions(store.getActions())).toEqual(
166+
clearStoreActions(expectedActions)
167+
)
168+
})
169+
170+
it('should call addInfiniteNotification and removeInfiniteNotification when errorCode is 11_114', async () => {
171+
const mockDatabaseId = '123'
172+
const error = {
173+
errorCode: CustomErrorCodes.CloudSubscriptionAlreadyExistsFree,
174+
resource: {
175+
databaseId: mockDatabaseId
176+
}
177+
};
178+
(oauthCloudJobSelector as jest.Mock).mockImplementation(() => ({
179+
status: ''
180+
}))
181+
182+
const { rerender } = render(<OAuthJobs />);
183+
184+
(oauthCloudJobSelector as jest.Mock).mockImplementation(() => ({
185+
status: CloudJobStatus.Failed,
186+
error,
187+
}))
188+
189+
rerender(<OAuthJobs />)
190+
191+
const expectedActions = [
192+
addInfiniteNotification(INFINITE_MESSAGES.DATABASE_EXISTS()),
193+
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
133194
]
134195
expect(clearStoreActions(store.getActions())).toEqual(
135196
clearStoreActions(expectedActions)

0 commit comments

Comments
 (0)