mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Unit tests for transfer error states
This commit is contained in:
parent
5d8d2a05c8
commit
9e390d3404
1 changed files with 81 additions and 20 deletions
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue