Add tests for override service

This commit is contained in:
Mark Kaylor 2023-04-21 16:53:49 +02:00
parent f33090461c
commit 924aca18f1
3 changed files with 78 additions and 2 deletions

View File

@ -41,7 +41,7 @@ const strapi = {
contentType: () => ({ info: {}, attributes: { test: { type: 'string' } } }),
};
describe('Build Component Schema', () => {
describe('Documentation plugin | Build component schema', () => {
beforeEach(() => {
// Reset the mocked strapi instance
global.strapi = _.cloneDeep(strapi);

View File

@ -34,7 +34,7 @@ jest.mock('fs-extra', () => ({
ensureFile: jest.fn(),
}));
describe('Documentation service', () => {
describe('Documentation plugin | Documentation service', () => {
beforeAll(() => {
global.strapi = mockStrapiInstance;
global.strapi.contentType = jest.fn((uid) => {

View File

@ -0,0 +1,76 @@
'use strict';
const override = require('../override');
const strapi = {
config: {
get: () => ({
'x-strapi-config': {
plugins: null,
},
}),
},
};
describe('Documentation plugin | Override service', () => {
it('should register an override', () => {
const mockOverride = {
openapi: '3.0.0',
info: {
title: 'My API',
version: '1.0.0',
},
};
const overrideService = override({ strapi });
overrideService.registerOverride(mockOverride);
expect(overrideService.registeredOverrides).toEqual([mockOverride]);
});
it('should not register an override from a plugin that is not in the config', () => {
const mockOverride = {
openapi: '3.0.0',
info: {
title: 'My API',
version: '1.0.0',
},
};
const overrideService = override({ strapi });
overrideService.registerOverride(mockOverride, { pluginOrigin: 'test' });
expect(overrideService.registeredOverrides).toEqual([]);
});
it('should register an override from a plugin that is in the config and exclude it from generation', () => {
const mockOverride = {
openapi: '3.0.0',
info: {
title: 'My API',
version: '1.0.0',
},
};
strapi.config.get = () => ({
'x-strapi-config': {
plugins: ['test'],
},
});
const overrideService = override({ strapi });
overrideService.registerOverride(mockOverride, {
pluginOrigin: 'test',
excludeFromGeneration: ['test', 'some-other-api-to-exclude'],
});
expect(overrideService.registeredOverrides).toEqual([mockOverride]);
expect(overrideService.excludedFromGeneration).toEqual(['test', 'some-other-api-to-exclude']);
});
it('should register an api or plugin to exclude from generation', () => {
const overrideService = override({ strapi });
overrideService.excludeFromGeneration('my-api');
overrideService.excludeFromGeneration(['my-other-api', 'my-plugin', 'my-other-plugin']);
expect(overrideService.excludedFromGeneration).toEqual([
'my-api',
'my-other-api',
'my-plugin',
'my-other-plugin',
]);
});
});