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,26 +406,87 @@ describe('acceptInvitation', () => {
expect(state.studio.invited).toBe(true);
expect(state.studio.curator).toBe(false);
});
});
describe('transferHost', () => {
beforeEach(() => {
store = configureStore(reducers, {
...initialState,
studio: {
id: 123123,
managers: 3
}
});
});
test('transfers the host on success', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {}, {statusCode: 200});
});
await store.dispatch(transferHost('password', 'newHostName', 'newHostId'));
const state = store.getState();
expect(api.mock.calls[0][0].uri).toBe('/studios/123123/transfer/newHostName');
expect(state.studio.owner).toBe('newHostId');
describe('transferHost', () => {
beforeEach(() => {
store = configureStore(reducers, {
...initialState,
studio: {
id: 123123,
managers: 3,
owner: 'oldHost'
}
});
});
test('transfers the host on success', async () => {
api.mockImplementation((opts, callback) => {
callback(null, {}, {statusCode: 200});
});
await store.dispatch(transferHost('password', 'newHostName', 'newHostId'));
const state = store.getState();
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');
});
});