Skip to content

Commit

Permalink
remi feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
markkaylor committed May 10, 2022
1 parent 5616903 commit acd8b1a
Showing 1 changed file with 35 additions and 86 deletions.
@@ -1,12 +1,16 @@
'use strict';

const _ = require('lodash');
const buildComponentSchema = require('../server/services/helpers/build-component-schema');
const strapi = require('../__mocks__/strapi');

describe('Build Component Schema', () => {
it('builds the Response schema', () => {
global.strapi = strapi;
beforeEach(() => {
// Reset the mocked strapi instance
global.strapi = _.cloneDeep(strapi);
});

it('builds the Response schema', () => {
const apiMocks = [
{
name: 'users-permissions',
Expand All @@ -16,7 +20,7 @@ describe('Build Component Schema', () => {
{ name: 'restaurant', getter: 'api', ctNames: ['restaurant'] },
];

let schemas;
let schemas = {};
for (const mock of apiMocks) {
schemas = {
...schemas,
Expand Down Expand Up @@ -49,25 +53,12 @@ describe('Build Component Schema', () => {
});

it('builds the ResponseList schema', () => {
global.strapi = {
...strapi,
plugins: {
'users-permissions': {
...strapi.plugins['users-permissions'],
routes: {
'content-api': { routes: [{ method: 'GET', path: '/test', handler: 'test.find' }] },
},
},
},
api: {
restaurant: {
...strapi.api.restaurant,
routes: {
restaurant: { routes: [{ method: 'GET', path: '/test', handler: 'test.find' }] },
},
},
},
};
global.strapi.plugins['users-permissions'].routes['content-api'].routes = [
{ method: 'GET', path: '/test', handler: 'test.find' },
];
global.strapi.api.restaurant.routes.restaurant.routes = [
{ method: 'GET', path: '/test', handler: 'test.find' },
];

const apiMocks = [
{
Expand All @@ -78,7 +69,7 @@ describe('Build Component Schema', () => {
{ name: 'restaurant', getter: 'api', ctNames: ['restaurant'] },
];

let schemas;
let schemas = {};
for (const mock of apiMocks) {
schemas = {
...schemas,
Expand Down Expand Up @@ -126,25 +117,12 @@ describe('Build Component Schema', () => {
});

it('builds the Request schema', () => {
global.strapi = {
...strapi,
plugins: {
'users-permissions': {
...strapi.plugins['users-permissions'],
routes: {
'content-api': { routes: [{ method: 'POST', path: '/test', handler: 'test.create' }] },
},
},
},
api: {
restaurant: {
...strapi.api.restaurant,
routes: {
restaurant: { routes: [{ method: 'POST', path: '/test', handler: 'test.create' }] },
},
},
},
};
global.strapi.plugins['users-permissions'].routes['content-api'].routes = [
{ method: 'POST', path: '/test', handler: 'test.create' },
];
global.strapi.api.restaurant.routes.restaurant.routes = [
{ method: 'POST', path: '/test', handler: 'test.create' },
];

const apiMocks = [
{
Expand All @@ -155,7 +133,7 @@ describe('Build Component Schema', () => {
{ name: 'restaurant', getter: 'api', ctNames: ['restaurant'] },
];

let schemas;
let schemas = {};
for (const mock of apiMocks) {
schemas = {
...schemas,
Expand Down Expand Up @@ -185,25 +163,12 @@ describe('Build Component Schema', () => {
});

it('builds the LocalizationResponse schema', () => {
global.strapi = {
...strapi,
plugins: {
'users-permissions': {
...strapi.plugins['users-permissions'],
routes: {
'content-api': { routes: [{ method: 'GET', path: '/localizations', handler: 'test' }] },
},
},
},
api: {
restaurant: {
...strapi.api.restaurant,
routes: {
restaurant: { routes: [{ method: 'GET', path: '/localizations', handler: 'test' }] },
},
},
},
};
global.strapi.plugins['users-permissions'].routes['content-api'].routes = [
{ method: 'GET', path: '/localizations', handler: 'test' },
];
global.strapi.api.restaurant.routes.restaurant.routes = [
{ method: 'GET', path: '/localizations', handler: 'test' },
];

const apiMocks = [
{
Expand All @@ -214,7 +179,7 @@ describe('Build Component Schema', () => {
{ name: 'restaurant', getter: 'api', ctNames: ['restaurant'] },
];

let schemas;
let schemas = {};
for (const mock of apiMocks) {
schemas = {
...schemas,
Expand Down Expand Up @@ -242,27 +207,12 @@ describe('Build Component Schema', () => {
});

it('builds the LocalizationRequest schema', () => {
global.strapi = {
...strapi,
plugins: {
'users-permissions': {
...strapi.plugins['users-permissions'],
routes: {
'content-api': {
routes: [{ method: 'POST', path: '/localizations', handler: 'test' }],
},
},
},
},
api: {
restaurant: {
...strapi.api.restaurant,
routes: {
restaurant: { routes: [{ method: 'POST', path: '/localizations', handler: 'test' }] },
},
},
},
};
global.strapi.plugins['users-permissions'].routes['content-api'].routes = [
{ method: 'POST', path: '/localizations', handler: 'test' },
];
global.strapi.api.restaurant.routes.restaurant.routes = [
{ method: 'POST', path: '/localizations', handler: 'test' },
];

const apiMocks = [
{
Expand All @@ -273,7 +223,7 @@ describe('Build Component Schema', () => {
{ name: 'restaurant', getter: 'api', ctNames: ['restaurant'] },
];

let schemas;
let schemas = {};
for (const mock of apiMocks) {
schemas = {
...schemas,
Expand All @@ -298,7 +248,6 @@ describe('Build Component Schema', () => {
});

it('creates the correct name given multiple content types', () => {
global.strapi = strapi;
const apiMock = {
name: 'users-permissions',
getter: 'plugin',
Expand Down

0 comments on commit acd8b1a

Please sign in to comment.