You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB

4 years ago
4 years ago
4 years ago
  1. import MockAdapter from 'axios-mock-adapter'
  2. import ProjectService from '@/services/project.service.js'
  3. describe('Project.service', () => {
  4. const mockAxios = new MockAdapter(ProjectService.request.instance)
  5. test('can get project list', async() => {
  6. const data = [
  7. {
  8. id: 1,
  9. name: 'CoNLL 2003',
  10. description: 'This is a project for NER.',
  11. guideline: 'Please write annotation guideline.',
  12. users: [1],
  13. project_type: 'SequenceLabeling',
  14. image: '/static/assets/images/cats/sequence_labeling.jpg',
  15. updated_at: '2019-07-09T06:19:29.789091Z',
  16. randomize_document_order: false,
  17. resourcetype: 'SequenceLabelingProject'
  18. }
  19. ]
  20. mockAxios.onGet('/projects').reply(200, data)
  21. const response = await ProjectService.getProjectList()
  22. expect(response).toEqual(data)
  23. })
  24. test('can create a project', async() => {
  25. const data = {
  26. name: 'test project',
  27. description: 'test description',
  28. guideline: 'Please write annotation guideline.',
  29. project_type: 'SequenceLabeling',
  30. randomize_document_order: false
  31. }
  32. mockAxios.onPost('/projects').reply(201, data)
  33. const response = await ProjectService.createProject(data)
  34. expect(response.title).toEqual(data.title)
  35. })
  36. test('can delete a project', async() => {
  37. const projectId = 1
  38. mockAxios.onDelete(`/projects/${projectId}`).reply(204, {})
  39. const response = await ProjectService.deleteProject(projectId)
  40. expect(response).toEqual({})
  41. })
  42. })