mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 06:04:29 +00:00
Add tests for override service
This commit is contained in:
parent
f33090461c
commit
924aca18f1
@ -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);
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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',
|
||||
]);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user