feat: Use vitest instead of jest for ESM compatibility

This commit is contained in:
Faruk AYDIN
2024-01-12 14:07:59 +01:00
parent 911159a14f
commit af9ceac0b4
19 changed files with 655 additions and 66 deletions

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import * as license from '../../helpers/license.ee';
@@ -22,10 +22,10 @@ describe('graphQL getAutomatischInfo query', () => {
describe('and without valid license', () => {
beforeEach(async () => {
jest.spyOn(license, 'getLicense').mockResolvedValue(false);
vi.spyOn(license, 'getLicense').mockResolvedValue(false);
jest.replaceProperty(appConfig, 'isCloud', false);
jest.replaceProperty(appConfig, 'isMation', false);
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(false);
});
it('should return empty license data', async () => {
@@ -62,12 +62,12 @@ describe('graphQL getAutomatischInfo query', () => {
verified: true,
};
jest.spyOn(license, 'getLicense').mockResolvedValue(mockedLicense);
vi.spyOn(license, 'getLicense').mockResolvedValue(mockedLicense);
});
describe('and with cloud flag enabled', () => {
beforeEach(async () => {
jest.replaceProperty(appConfig, 'isCloud', true);
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
});
it('should return all license data', async () => {
@@ -97,7 +97,7 @@ describe('graphQL getAutomatischInfo query', () => {
describe('and with cloud flag disabled', () => {
beforeEach(async () => {
jest.replaceProperty(appConfig, 'isCloud', false);
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
});
it('should return all license data', async () => {
@@ -127,8 +127,8 @@ describe('graphQL getAutomatischInfo query', () => {
describe('and with mation flag enabled', () => {
beforeEach(async () => {
jest.replaceProperty(appConfig, 'isCloud', false);
jest.replaceProperty(appConfig, 'isMation', true);
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(true);
});
it('should return all license data', async () => {
@@ -158,8 +158,8 @@ describe('graphQL getAutomatischInfo query', () => {
describe('and with mation flag disabled', () => {
beforeEach(async () => {
jest.replaceProperty(appConfig, 'isCloud', false);
jest.replaceProperty(appConfig, 'isMation', false);
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
vi.spyOn(appConfig, 'isMation', 'get').mockReturnValue(false);
});
it('should return all license data', async () => {

View File

@@ -1,14 +1,11 @@
import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import { createConfig } from '../../../test/factories/config';
import { IConfig } from '@automatisch/types';
import * as license from '../../helpers/license.ee';
describe('graphQL getConfig query', () => {
let configOne: IConfig,
configTwo: IConfig,
configThree: IConfig,
query: string;
let configOne, configTwo, configThree, query;
beforeEach(async () => {
configOne = await createConfig({ key: 'configOne' });
@@ -24,7 +21,7 @@ describe('graphQL getConfig query', () => {
describe('and without valid license', () => {
beforeEach(async () => {
jest.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
});
describe('and correct permissions', () => {
@@ -43,7 +40,7 @@ describe('graphQL getConfig query', () => {
describe('and with valid license', () => {
beforeEach(async () => {
jest.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
});
describe('and without providing specific keys', () => {

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import appConfig from '../../config/app';

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import appConfig from '../../config/app';

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
@@ -94,7 +94,7 @@ describe('graphQL getRole query', () => {
describe('with authenticated user', () => {
describe('and with valid license', () => {
beforeEach(async () => {
jest.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
});
describe('and without permissions', () => {
@@ -162,7 +162,7 @@ describe('graphQL getRole query', () => {
describe('and without valid license', () => {
beforeEach(async () => {
jest.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
});
describe('and correct permissions', () => {

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
@@ -73,7 +73,7 @@ describe('graphQL getRoles query', () => {
describe('with authenticated user', () => {
describe('and with valid license', () => {
beforeEach(async () => {
jest.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
});
describe('and without permissions', () => {
@@ -132,7 +132,7 @@ describe('graphQL getRoles query', () => {
describe('and without valid license', () => {
beforeEach(async () => {
jest.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(false);
});
describe('and correct permissions', () => {

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import User from '../../models/user';
@@ -41,9 +41,9 @@ describe('graphQL getTrialStatus query', () => {
userToken = createAuthTokenByUserId(user.id);
});
describe('and with cloud flag disabled', () => {
describe.only('and with cloud flag disabled', () => {
beforeEach(async () => {
jest.replaceProperty(appConfig, 'isCloud', false);
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(false);
});
it('should return null', async () => {
@@ -63,15 +63,15 @@ describe('graphQL getTrialStatus query', () => {
describe('and with cloud flag enabled', () => {
beforeEach(async () => {
jest.replaceProperty(appConfig, 'isCloud', true);
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
});
describe('and not in trial and has active subscription', () => {
beforeEach(async () => {
jest.spyOn(User.prototype, 'inTrial').mockResolvedValue(false);
jest
.spyOn(User.prototype, 'hasActiveSubscription')
.mockResolvedValue(true);
vi.spyOn(User.prototype, 'inTrial').mockResolvedValue(false);
vi.spyOn(User.prototype, 'hasActiveSubscription').mockResolvedValue(
true
);
});
it('should return null', async () => {
@@ -91,7 +91,7 @@ describe('graphQL getTrialStatus query', () => {
describe('and in trial period', () => {
beforeEach(async () => {
jest.spyOn(User.prototype, 'inTrial').mockResolvedValue(true);
vi.spyOn(User.prototype, 'inTrial').mockResolvedValue(true);
});
it('should return null', async () => {

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../app';
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';

View File

@@ -1,4 +1,4 @@
// @ts-nocheck
import { describe, it, expect } from 'vitest';
import request from 'supertest';
import app from '../../app';
import appConfig from '../../config/app';