Merge pull request #1362 from automatisch/test/get-automatisch-info
test: Add getAutomatischInfo graphQL query tests
This commit is contained in:
@@ -0,0 +1,120 @@
|
|||||||
|
import { setMockConfig } from '../../../test/setup/set-mock-config';
|
||||||
|
import request from 'supertest';
|
||||||
|
import app from '../../app';
|
||||||
|
import * as license from '../../helpers/license.ee';
|
||||||
|
|
||||||
|
describe('graphQL getAutomatischInfo query', () => {
|
||||||
|
const query = `
|
||||||
|
query {
|
||||||
|
getAutomatischInfo {
|
||||||
|
isCloud
|
||||||
|
license {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
expireAt
|
||||||
|
verified
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
describe('and without valid license', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.spyOn(license, 'getLicense').mockResolvedValue(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return empty license data', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getAutomatischInfo: {
|
||||||
|
isCloud: false,
|
||||||
|
license: {
|
||||||
|
id: null as string,
|
||||||
|
name: null as string,
|
||||||
|
expireAt: null as string,
|
||||||
|
verified: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with valid license', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const mockedLicense = {
|
||||||
|
id: '123123',
|
||||||
|
name: 'Test License',
|
||||||
|
expireAt: '2025-08-09T10:56:54.144Z',
|
||||||
|
verified: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
jest.spyOn(license, 'getLicense').mockResolvedValue(mockedLicense);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with cloud flag enabled', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
setMockConfig({ isCloud: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return all license data', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getAutomatischInfo: {
|
||||||
|
isCloud: true,
|
||||||
|
license: {
|
||||||
|
expireAt: '2025-08-09T10:56:54.144Z',
|
||||||
|
id: '123123',
|
||||||
|
name: 'Test License',
|
||||||
|
verified: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and with cloud flag disabled', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
setMockConfig({ isCloud: false });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return all license data', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post('/graphql')
|
||||||
|
.send({ query })
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedResponsePayload = {
|
||||||
|
data: {
|
||||||
|
getAutomatischInfo: {
|
||||||
|
isCloud: false,
|
||||||
|
license: {
|
||||||
|
expireAt: '2025-08-09T10:56:54.144Z',
|
||||||
|
id: '123123',
|
||||||
|
name: 'Test License',
|
||||||
|
verified: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedResponsePayload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -1,6 +1,16 @@
|
|||||||
import { Model } from 'objection';
|
import { Model } from 'objection';
|
||||||
import { client as knex } from '../../src/config/database';
|
import { client as knex } from '../../src/config/database';
|
||||||
import logger from '../../src/helpers/logger';
|
import logger from '../../src/helpers/logger';
|
||||||
|
import { mockConfigState, resetMockConfig } from './set-mock-config';
|
||||||
|
|
||||||
|
jest.mock('../../src/config/app', () => ({
|
||||||
|
...jest.requireActual('../../src/config/app').default,
|
||||||
|
get isCloud() {
|
||||||
|
return mockConfigState.isCloud !== undefined
|
||||||
|
? mockConfigState.isCloud
|
||||||
|
: jest.requireActual('../../src/config/app').default.isCloud;
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
global.beforeAll(async () => {
|
global.beforeAll(async () => {
|
||||||
global.knex = null;
|
global.knex = null;
|
||||||
@@ -21,6 +31,9 @@ global.beforeEach(async () => {
|
|||||||
global.afterEach(async () => {
|
global.afterEach(async () => {
|
||||||
await global.knex.rollback();
|
await global.knex.rollback();
|
||||||
Model.knex(knex);
|
Model.knex(knex);
|
||||||
|
|
||||||
|
jest.clearAllMocks();
|
||||||
|
resetMockConfig();
|
||||||
});
|
});
|
||||||
|
|
||||||
global.afterAll(async () => {
|
global.afterAll(async () => {
|
||||||
|
13
packages/backend/test/setup/set-mock-config.ts
Normal file
13
packages/backend/test/setup/set-mock-config.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
export const mockConfigState = {
|
||||||
|
isCloud: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resetMockConfig = () => {
|
||||||
|
for (const key in mockConfigState) {
|
||||||
|
delete (mockConfigState as any)[key];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setMockConfig = (config: Partial<typeof mockConfigState>) => {
|
||||||
|
Object.assign(mockConfigState, config);
|
||||||
|
};
|
Reference in New Issue
Block a user