e6959004c9
Migrated webpack to vite. Replaced jest with vitest (because I couldn't resolve 'import.meta' issue) Replaced legacy vue-svg-loader with vite-svg-loader Replaced bip39 dep with bip39-english (it includes only english wordlist) Replaced aws-sdk v2 with aws-sdk V3 (because v2 was throwing some weird error in console. Ref: https://stackoverflow.com/questions/75107933/aws-sdk-contributes-to-build-error-uncaught-typeerror-e-is-not-a-constructor) Renamed VUE_APP_ENDPOINT_URL env variable to VITE_ENDPOINT_URL Removed a ton of dependencies (like babel and jest-related stuff). Tested in Chrome, Safari, Brave, Firefox and Opera browsers. Additionally fixed logout errors from buckets and object browser routes. TODO: try to remove util and stream-browserify dependencies and see if it works Change-Id: I4562649a59eb0ba80c1a672d55c59fceb8c80b23
165 lines
4.7 KiB
TypeScript
165 lines
4.7 KiB
TypeScript
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
import { vi } from 'vitest';
|
|
import { createPinia, setActivePinia } from 'pinia';
|
|
|
|
import { ProjectsApiGql } from '@/api/projects';
|
|
import { Project, ProjectFields, ProjectLimits } from '@/types/projects';
|
|
import { useProjectsStore } from '@/store/modules/projectsStore';
|
|
|
|
const limits = new ProjectLimits(15, 12, 14, 13);
|
|
const project = new Project('11', 'name', 'descr', '23', 'testOwnerId');
|
|
const projects = [
|
|
new Project(
|
|
'11',
|
|
'name',
|
|
'descr',
|
|
'23',
|
|
'testOwnerId',
|
|
false,
|
|
),
|
|
new Project(
|
|
'1',
|
|
'name2',
|
|
'descr2',
|
|
'24',
|
|
'testOwnerId1',
|
|
false,
|
|
),
|
|
];
|
|
|
|
describe('actions', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia());
|
|
vi.resetAllMocks();
|
|
});
|
|
|
|
it('select project', () => {
|
|
const store = useProjectsStore();
|
|
|
|
store.state.projects = projects;
|
|
store.selectProject('11');
|
|
|
|
expect(store.state.selectedProject.id).toBe('11');
|
|
expect(store.state.currentLimits.bandwidthLimit).toBe(0);
|
|
});
|
|
|
|
it('success fetch projects', async () => {
|
|
const store = useProjectsStore();
|
|
|
|
vi.spyOn(ProjectsApiGql.prototype, 'get').mockReturnValue(
|
|
Promise.resolve(projects),
|
|
);
|
|
|
|
await store.getProjects();
|
|
|
|
expect(store.state.projects).toStrictEqual(projects);
|
|
});
|
|
|
|
it('fetch throws an error when api call fails', async () => {
|
|
const store = useProjectsStore();
|
|
|
|
vi.spyOn(ProjectsApiGql.prototype, 'get').mockImplementation(() => { throw new Error(); });
|
|
|
|
try {
|
|
await store.getProjects();
|
|
} catch (error) {
|
|
expect(store.state.projects.length).toBe(0);
|
|
expect(store.state.currentLimits.bandwidthLimit).toBe(0);
|
|
}
|
|
});
|
|
|
|
it('success create project', async () => {
|
|
const store = useProjectsStore();
|
|
|
|
vi.spyOn(ProjectsApiGql.prototype, 'create').mockReturnValue(
|
|
Promise.resolve(project),
|
|
);
|
|
|
|
await store.createProject(new ProjectFields());
|
|
|
|
expect(store.state.projects.length).toBe(1);
|
|
expect(store.state.currentLimits.bandwidthLimit).toBe(0);
|
|
});
|
|
|
|
it('create throws an error when create api call fails', async () => {
|
|
const store = useProjectsStore();
|
|
|
|
vi.spyOn(ProjectsApiGql.prototype, 'create').mockImplementation(() => { throw new Error(); });
|
|
|
|
try {
|
|
await store.createProject(new ProjectFields());
|
|
expect(true).toBe(false);
|
|
} catch (error) {
|
|
expect(store.state.projects.length).toBe(0);
|
|
expect(store.state.currentLimits.bandwidthLimit).toBe(0);
|
|
}
|
|
});
|
|
|
|
it('success update project name', async () => {
|
|
const store = useProjectsStore();
|
|
|
|
vi.spyOn(ProjectsApiGql.prototype, 'update').mockReturnValue(
|
|
Promise.resolve(),
|
|
);
|
|
|
|
store.state.selectedProject = projects[0];
|
|
const newName = 'newName';
|
|
const fieldsToUpdate = new ProjectFields(newName, projects[0].description);
|
|
|
|
await store.updateProjectName(fieldsToUpdate);
|
|
|
|
expect(store.state.selectedProject.name).toBe(newName);
|
|
});
|
|
|
|
it('success update project description', async () => {
|
|
const store = useProjectsStore();
|
|
|
|
vi.spyOn(ProjectsApiGql.prototype, 'update').mockReturnValue(
|
|
Promise.resolve(),
|
|
);
|
|
|
|
store.state.selectedProject = projects[0];
|
|
const newDescription = 'newDescription1';
|
|
const fieldsToUpdate = new ProjectFields(projects[0].name, newDescription);
|
|
|
|
await store.updateProjectDescription(fieldsToUpdate);
|
|
|
|
expect(store.state.selectedProject.description).toBe(newDescription);
|
|
});
|
|
|
|
it('success get project limits', async () => {
|
|
const store = useProjectsStore();
|
|
|
|
vi.spyOn(ProjectsApiGql.prototype, 'getLimits').mockReturnValue(
|
|
Promise.resolve(limits),
|
|
);
|
|
|
|
store.state.projects = projects;
|
|
|
|
await store.getProjectLimits(store.state.selectedProject.id);
|
|
|
|
expect(store.state.currentLimits.bandwidthUsed).toBe(12);
|
|
expect(store.state.currentLimits.bandwidthLimit).toBe(15);
|
|
expect(store.state.currentLimits.storageUsed).toBe(13);
|
|
expect(store.state.currentLimits.storageLimit).toBe(14);
|
|
});
|
|
});
|
|
|
|
describe('getters', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia());
|
|
});
|
|
|
|
it('projects array', () => {
|
|
const store = useProjectsStore();
|
|
|
|
store.state.projects = projects;
|
|
|
|
const allProjects = store.projects;
|
|
|
|
expect(allProjects.length).toEqual(2);
|
|
});
|
|
});
|