|
| 1 | +import request from 'supertest'; |
| 2 | +import { setupPublicApiTests, createTokenForUser } from './helpers'; |
| 3 | +import { Keyword } from '../../../src/entity/Keyword'; |
| 4 | + |
| 5 | +const state = setupPublicApiTests(); |
| 6 | + |
| 7 | +describe('GET /public/v1/tags', () => { |
| 8 | + beforeEach(async () => { |
| 9 | + await state.con.getRepository(Keyword).save([ |
| 10 | + { value: 'eng688tagalpha', status: 'allow' }, |
| 11 | + { value: 'eng688tagbeta', status: 'allow' }, |
| 12 | + ]); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should return all tags for authenticated user', async () => { |
| 16 | + const token = await createTokenForUser(state.con, '5'); |
| 17 | + |
| 18 | + const { body } = await request(state.app.server) |
| 19 | + .get('/public/v1/tags') |
| 20 | + .set('Authorization', `Bearer ${token}`) |
| 21 | + .expect(200); |
| 22 | + |
| 23 | + expect(Array.isArray(body.data)).toBe(true); |
| 24 | + expect(body.data).toEqual( |
| 25 | + expect.arrayContaining([ |
| 26 | + { name: 'eng688tagalpha' }, |
| 27 | + { name: 'eng688tagbeta' }, |
| 28 | + ]), |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should return 401 without auth header', async () => { |
| 33 | + await request(state.app.server).get('/public/v1/tags').expect(401); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should return data array without pagination', async () => { |
| 37 | + const token = await createTokenForUser(state.con, '5'); |
| 38 | + |
| 39 | + const { body } = await request(state.app.server) |
| 40 | + .get('/public/v1/tags') |
| 41 | + .set('Authorization', `Bearer ${token}`) |
| 42 | + .expect(200); |
| 43 | + |
| 44 | + expect(body).toMatchObject({ |
| 45 | + data: expect.any(Array), |
| 46 | + }); |
| 47 | + expect(body.pagination).toBeUndefined(); |
| 48 | + }); |
| 49 | +}); |
0 commit comments