Guest User

Untitled

a guest
Jan 26th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import request from 'supertest'
  2. import randomString from 'random-string'
  3. import {
  4. uuid
  5. } from '../../../utils/uuid'
  6. import {
  7. models
  8. } from '../../../models'
  9.  
  10. const app = require('../../../app')
  11.  
  12. let user
  13.  
  14. beforeAll(async () => {
  15. // 사용자 2명 생성
  16. await models.User.create({
  17. email: randomString() + '@test.com',
  18. password: randomString()
  19. })
  20.  
  21. user = await models.User.create({
  22. email: randomString() + '@test.com',
  23. password: randomString()
  24. })
  25. })
  26.  
  27. afterAll(() => models.sequelize.close())
  28.  
  29. describe('GET: /v1/users', () => {
  30.  
  31. test('전체 사용자 조회. | 200', async () => {
  32. let response = await request(app)
  33. .get(`/v1/users`)
  34.  
  35. expect(response.body.length)
  36. .toBeGreaterThan(1)
  37. })
  38.  
  39. test('uuid 로 사용자 조회. | 200', async () => {
  40. let response = await request(app)
  41. .get(`/v1/users/${user.uuid}`)
  42.  
  43. expect(response.body.email)
  44. .toBe(user.email)
  45. })
  46.  
  47. test('잘못된 uuid 로 사용자 조회. | 404', async () => {
  48. let response = await request(app)
  49. .get(`/v1/users/${uuid()}`)
  50.  
  51. expect(response.statusCode)
  52. .toBe(404)
  53. })
  54. })
Add Comment
Please, Sign In to add comment