2019-08-15 19:21:46 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-08-19 11:00:38 +01:00
|
|
|
import ApiKeysArea from '@/components/apiKeys/ApiKeysArea.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2020-01-22 14:10:35 +00:00
|
|
|
import { PaymentsHttpApi } from '@/api/payments';
|
2019-09-12 15:10:50 +01:00
|
|
|
import { API_KEYS_MUTATIONS, makeApiKeysModule } from '@/store/modules/apiKeys';
|
2019-08-29 11:05:22 +01:00
|
|
|
import { makeNotificationsModule } from '@/store/modules/notifications';
|
2020-01-22 14:10:35 +00:00
|
|
|
import { makePaymentsModule } from '@/store/modules/payments';
|
2019-10-17 11:34:45 +01:00
|
|
|
import { makeProjectsModule } from '@/store/modules/projects';
|
2020-06-02 17:38:44 +01:00
|
|
|
import { ApiKey, ApiKeyOrderBy, ApiKeysPage } from '@/types/apiKeys';
|
|
|
|
import { SortDirection } from '@/types/common';
|
2019-10-17 11:34:45 +01:00
|
|
|
import { Project } from '@/types/projects';
|
2020-01-08 15:58:28 +00:00
|
|
|
import { NotificatorPlugin } from '@/utils/plugins/notificator';
|
2019-12-11 20:07:15 +00:00
|
|
|
import { SegmentioPlugin } from '@/utils/plugins/segment';
|
2020-02-24 16:09:27 +00:00
|
|
|
import { createLocalVue, mount, shallowMount } from '@vue/test-utils';
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
import { ApiKeysMock } from '../mock/api/apiKeys';
|
|
|
|
import { ProjectsApiMock } from '../mock/api/projects';
|
|
|
|
|
2019-08-15 19:21:46 +01:00
|
|
|
const localVue = createLocalVue();
|
2019-12-11 20:07:15 +00:00
|
|
|
const segmentioPlugin = new SegmentioPlugin();
|
2020-01-08 15:58:28 +00:00
|
|
|
const notificationPlugin = new NotificatorPlugin();
|
2019-08-15 19:21:46 +01:00
|
|
|
localVue.use(Vuex);
|
2019-12-11 20:07:15 +00:00
|
|
|
localVue.use(segmentioPlugin);
|
2020-01-08 15:58:28 +00:00
|
|
|
localVue.use(notificationPlugin);
|
2019-10-17 11:34:45 +01:00
|
|
|
|
|
|
|
const apiKeysApi = new ApiKeysMock();
|
2019-08-19 11:00:38 +01:00
|
|
|
const apiKeysModule = makeApiKeysModule(apiKeysApi);
|
2019-10-17 11:34:45 +01:00
|
|
|
const projectsApi = new ProjectsApiMock();
|
|
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
2020-01-22 14:10:35 +00:00
|
|
|
const paymentsApi = new PaymentsHttpApi();
|
|
|
|
const paymentsModule = makePaymentsModule(paymentsApi);
|
2019-08-29 11:05:22 +01:00
|
|
|
const notificationsModule = makeNotificationsModule();
|
2019-10-17 11:34:45 +01:00
|
|
|
const { CLEAR, SET_PAGE } = API_KEYS_MUTATIONS;
|
2020-01-22 14:10:35 +00:00
|
|
|
const store = new Vuex.Store({ modules: { projectsModule, apiKeysModule, paymentsModule, notificationsModule }});
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
describe('ApiKeysArea', (): void => {
|
2019-10-22 12:12:49 +01:00
|
|
|
const project = new Project('id', 'projectName', 'projectDescription', 'test', 'testOwnerId', true);
|
2019-10-17 11:34:45 +01:00
|
|
|
projectsApi.setMockProjects([project]);
|
|
|
|
|
2020-09-28 14:44:01 +01:00
|
|
|
const date = new Date(0);
|
|
|
|
const apiKey = new ApiKey('testId', 'test', date, 'test');
|
|
|
|
const apiKey1 = new ApiKey('testId1', 'test1', date, 'test1');
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
const testApiKeysPage = new ApiKeysPage([apiKey], '', ApiKeyOrderBy.NAME, SortDirection.ASCENDING, 6, 1, 1, 2);
|
2019-10-17 11:34:45 +01:00
|
|
|
apiKeysApi.setMockApiKeysPage(testApiKeysPage);
|
2019-09-12 15:10:50 +01:00
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('renders correctly', (): void => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function apiKeyList works correctly', (): void => {
|
2019-09-12 15:10:50 +01:00
|
|
|
store.commit(SET_PAGE, testApiKeysPage);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyList).toEqual([apiKey]);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('action on toggleSelection works correctly', async (): Promise<void> => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.toggleSelection(apiKey);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
expect(store.getters.selectedApiKeys.length).toBe(1);
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('action on onClearSelection works correctly', async (): Promise<void> => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.onClearSelection();
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function onCreateApiKeyClick works correctly', async (): Promise<void> => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.onCreateApiKeyClick();
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isNewApiKeyPopupShown).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function onDeleteClick works correctly', async (): Promise<void> => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
await wrapper.vm.toggleSelection(apiKey);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
await wrapper.find('.deletion').trigger('click');
|
2019-08-15 19:21:46 +01:00
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(true);
|
2020-06-02 17:38:44 +01:00
|
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
await wrapper.find('.deletion').trigger('click');
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(false);
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
await wrapper.vm.onClearSelection();
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function apiKeyCountTitle works correctly', (): void => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyCountTitle).toMatch('api key');
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function isEmpty works correctly', (): void => {
|
2019-09-12 15:10:50 +01:00
|
|
|
store.commit(SET_PAGE, testApiKeysPage);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.isEmpty).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function selectedAPIKeysCount works correctly', (): void => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.selectedAPIKeysCount).toBe(0);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function headerState works correctly', (): void => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.headerState).toBe(0);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function apiKeyCountTitle with 2 keys works correctly', (): void => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const testPage = new ApiKeysPage();
|
|
|
|
testPage.apiKeys = [apiKey, apiKey1];
|
|
|
|
testPage.totalCount = 1;
|
|
|
|
testPage.pageCount = 1;
|
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
apiKeysApi.setMockApiKeysPage(testPage);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyCountTitle).toMatch('api keys');
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function closeNewApiKeyPopup works correctly', async (): Promise<void> => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.closeNewApiKeyPopup();
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isNewApiKeyPopupShown).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function showCopyApiKeyPopup works correctly', async (): Promise<void> => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
const testSecret = 'testSecret';
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.showCopyApiKeyPopup(testSecret);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isCopyApiKeyPopupShown).toBe(true);
|
|
|
|
expect(wrapper.vm.$data.apiKeySecret).toMatch('testSecret');
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('function closeCopyNewApiKeyPopup works correctly', async (): Promise<void> => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.closeCopyNewApiKeyPopup();
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isCopyApiKeyPopupShown).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('renders empty screen with add key prompt', (): void => {
|
2020-02-24 16:09:27 +00:00
|
|
|
store.commit(CLEAR);
|
|
|
|
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
2019-10-17 11:34:45 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-06-02 17:38:44 +01:00
|
|
|
it('renders empty search state correctly', (): void => {
|
2019-10-17 11:34:45 +01:00
|
|
|
const testPage = new ApiKeysPage();
|
|
|
|
testPage.apiKeys = [];
|
|
|
|
testPage.totalCount = 0;
|
|
|
|
testPage.pageCount = 0;
|
|
|
|
testPage.search = 'testSearch';
|
|
|
|
apiKeysApi.setMockApiKeysPage(testPage);
|
|
|
|
|
|
|
|
store.commit(SET_PAGE, testPage);
|
|
|
|
|
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|