Unit tests for transfer error states

This commit is contained in:
seotts 2021-09-07 13:28:20 -04:00
parent 5d8d2a05c8
commit 9e390d3404

View file

@ -293,7 +293,7 @@ describe('inviteCurator', () => {
});
test('error because of rate limit', async () => {
api.mockImplementation((opts, callback) => {
callback(null, null, {statusCode: 429});
callback(null, {}, {statusCode: 429});
});
await expect(store.dispatch(inviteCurator('user2')))
.rejects.toBe(Errors.RATE_LIMIT);
@ -406,14 +406,16 @@ describe('acceptInvitation', () => {
expect(state.studio.invited).toBe(true);
expect(state.studio.curator).toBe(false);
});
});
describe('transferHost', () => {
describe('transferHost', () => {
beforeEach(() => {
store = configureStore(reducers, {
...initialState,
studio: {
id: 123123,
managers: 3
managers: 3,
owner: 'oldHost'
}
});
});
@ -427,5 +429,64 @@ describe('acceptInvitation', () => {
expect(api.mock.calls[0][0].uri).toBe('/studios/123123/transfer/newHostName');
expect(state.studio.owner).toBe('newHostId');
});
test('error because of permissions issue', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {}, {statusCode: 403});
});
await expect(store.dispatch(transferHost('password', 'newHostName', 'newHostId')))
.rejects.toBe(Errors.PERMISSION);
const state = store.getState();
expect(state.studio.owner).toBe('oldHost');
});
test('error because of authorization issue', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {}, {statusCode: 401});
});
await expect(store.dispatch(transferHost('password', 'newHostName', 'newHostId')))
.rejects.toBe(Errors.PERMISSION);
const state = store.getState();
expect(state.studio.owner).toBe('oldHost');
});
test('error because of issue with new host', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {}, {statusCode: 409});
});
await expect(store.dispatch(transferHost('password', 'newHostName', 'newHostId')))
.rejects.toBe(Errors.CANNOT_BE_HOST);
const state = store.getState();
expect(state.studio.owner).toBe('oldHost');
});
test('error because of incorrect password', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {status: 'error', message: 'password incorrect'}, {statusCode: 401});
});
await expect(store.dispatch(transferHost('password', 'newHostName', 'newHostId')))
.rejects.toBe(Errors.PASSWORD);
const state = store.getState();
expect(state.studio.owner).toBe('oldHost');
});
test('error because of too many password attempts', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {status: 'error', message: 'try again later'}, {statusCode: 429});
});
await expect(store.dispatch(transferHost('password', 'newHostName', 'newHostId')))
.rejects.toBe(Errors.PASSWORD_ATTEMPT_LIMIT);
const state = store.getState();
expect(state.studio.owner).toBe('oldHost');
});
test('error because of rate limit', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {}, {statusCode: 429});
});
await expect(store.dispatch(transferHost('password', 'newHostName', 'newHostId')))
.rejects.toBe(Errors.RATE_LIMIT);
const state = store.getState();
expect(state.studio.owner).toBe('oldHost');
});
});