|
| 1 | +import { actions } from '../../src'; |
| 2 | + |
| 3 | +jest.mock('../../src/services/challenges'); |
| 4 | + |
| 5 | +const mockFetch = resolvesTo => jest.fn(() => |
| 6 | + Promise.resolve({ json: () => resolvesTo })); |
| 7 | + |
| 8 | +let originalFetch; |
| 9 | + |
| 10 | +beforeAll(() => { |
| 11 | + originalFetch = global.fetch; |
| 12 | +}); |
| 13 | + |
| 14 | +afterAll(() => { |
| 15 | + global.fetch = originalFetch; |
| 16 | +}); |
| 17 | + |
| 18 | +describe('challenge.fetchChallengeInit', () => { |
| 19 | + const a = actions.challenge.getDetailsInit(12345); |
| 20 | + |
| 21 | + test('has expected type', () => { |
| 22 | + expect(a.type).toBe('CHALLENGE/GET_DETAILS_INIT'); |
| 23 | + }); |
| 24 | + |
| 25 | + test('payload is the challenge ID, converted to string, if necessary', () => |
| 26 | + expect(a.payload).toBe('12345')); |
| 27 | +}); |
| 28 | + |
| 29 | +describe('challenge.fetchSubmissionsInit', () => { |
| 30 | + const a = actions.challenge.getSubmissionsInit(12345); |
| 31 | + |
| 32 | + test('has expected type', () => { |
| 33 | + expect(a.type).toBe('CHALLENGE/GET_SUBMISSIONS_INIT'); |
| 34 | + }); |
| 35 | + |
| 36 | + test('payload is challengeId', () => |
| 37 | + expect(a.payload).toBe('12345')); |
| 38 | +}); |
| 39 | + |
| 40 | +describe('challenge.getDetailsDone', () => { |
| 41 | + global.fetch = mockFetch({ result: { content: ['DUMMY DATA'] } }); |
| 42 | + |
| 43 | + const a = actions.challenge.getDetailsDone(12345); |
| 44 | + |
| 45 | + test('has expected type', () => { |
| 46 | + expect(a.type).toBe('CHALLENGE/GET_DETAILS_DONE'); |
| 47 | + }); |
| 48 | + |
| 49 | + const mockChallenge = |
| 50 | + require('../../src/services/__mocks__/data/challenge-normalized.json'); |
| 51 | + |
| 52 | + test('payload is a promise which resolves to the expected object', () => |
| 53 | + a.payload.then((res) => { |
| 54 | + res.communities = Array.from(res.communities); |
| 55 | + expect(res).toEqual(mockChallenge); |
| 56 | + })); |
| 57 | +}); |
| 58 | + |
| 59 | +describe('challenge.fetchSubmissionsDone', () => { |
| 60 | + global.fetch = mockFetch({ |
| 61 | + challengeId: '12345', |
| 62 | + submissions: 'DUMMY DATA', |
| 63 | + }); |
| 64 | + |
| 65 | + const a = actions.challenge.getSubmissionsDone(12345, {}); |
| 66 | + |
| 67 | + test('has expected type', () => { |
| 68 | + expect(a.type).toBe('CHALLENGE/GET_SUBMISSIONS_DONE'); |
| 69 | + }); |
| 70 | + |
| 71 | + test('payload is a promise which resolves to the expected object', () => |
| 72 | + a.payload.then(res => expect(res).toEqual({ |
| 73 | + challengeId: '12345', |
| 74 | + submissions: 'DUMMY DATA', |
| 75 | + }))); |
| 76 | +}); |
0 commit comments