summaryrefslogtreecommitdiff
path: root/spec/javascripts/import_projects/store/mutations_spec.js
blob: 8db8e9819baec562d164e991f9369a5513f085ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as types from '~/import_projects/store/mutation_types';
import mutations from '~/import_projects/store/mutations';

describe('import_projects store mutations', () => {
  describe(types.RECEIVE_IMPORT_SUCCESS, () => {
    it('removes repoId from reposBeingImported and providerRepos, adds to importedProjects', () => {
      const repoId = 1;
      const state = {
        reposBeingImported: [repoId],
        providerRepos: [{ id: repoId }],
        importedProjects: [],
      };
      const importedProject = { id: repoId };

      mutations[types.RECEIVE_IMPORT_SUCCESS](state, { importedProject, repoId });

      expect(state.reposBeingImported.includes(repoId)).toBe(false);
      expect(state.providerRepos.some(repo => repo.id === repoId)).toBe(false);
      expect(state.importedProjects.some(repo => repo.id === repoId)).toBe(true);
    });
  });

  describe(types.RECEIVE_JOBS_SUCCESS, () => {
    it('updates importStatus of existing importedProjects', () => {
      const repoId = 1;
      const state = { importedProjects: [{ id: repoId, importStatus: 'started' }] };
      const updatedProjects = [{ id: repoId, importStatus: 'finished' }];

      mutations[types.RECEIVE_JOBS_SUCCESS](state, updatedProjects);

      expect(state.importedProjects[0].importStatus).toBe(updatedProjects[0].importStatus);
    });
  });
});