Fix tests & make router config optional

This commit is contained in:
Alexandre Bodin 2023-09-15 15:47:05 +02:00
parent efc1c40f22
commit bac1fb9210
16 changed files with 84 additions and 66 deletions

View File

@ -4,12 +4,14 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
},
});

View File

@ -13,9 +13,11 @@ jest.mock('../../utils', () => ({
}));
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
features: {
isEnabled: jest.fn(),
get: jest.fn(),
default: {
features: {
isEnabled: jest.fn(),
get: jest.fn(),
},
},
}));

View File

@ -20,9 +20,11 @@ describe('Passport', () => {
describe('Init (SSO disabled)', () => {
beforeAll(() => {
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
features: {
// Disable the SSO feature
isEnabled: (feature) => feature !== 'sso',
default: {
features: {
// Disable the SSO feature
isEnabled: (feature) => feature !== 'sso',
},
},
}));
});
@ -58,9 +60,11 @@ describe('Passport', () => {
describe('Init (SSO enabled)', () => {
beforeAll(() => {
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
features: {
// Enable all the features (including SSO)
isEnabled: () => true,
default: {
features: {
// Enable all the features (including SSO)
isEnabled: () => true,
},
},
}));
});

View File

@ -4,12 +4,14 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
},
});

View File

@ -1,12 +1,14 @@
'use strict';
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
features: {
isEnabled() {
return true;
},
list() {
return [{ name: 'sso' }];
default: {
features: {
isEnabled() {
return true;
},
list() {
return [{ name: 'sso' }];
},
},
},
}));

View File

@ -4,12 +4,14 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
},
});

View File

@ -4,12 +4,14 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
},
});

View File

@ -7,9 +7,11 @@ let ssoEnabled = true;
jest.mock('@strapi/strapi/dist/utils/ee', () => {
return {
features: {
isEnabled() {
return ssoEnabled;
default: {
features: {
isEnabled() {
return ssoEnabled;
},
},
},
};

View File

@ -4,12 +4,14 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => false;
Object.assign(eeModule, {
features: {
isEnabled() {
return false;
},
list() {
return [];
default: {
features: {
isEnabled() {
return false;
},
list() {
return [];
},
},
},
});

View File

@ -11,10 +11,9 @@ import { exitWith } from './helpers';
/**
* argParser: Parse a comma-delimited string as an array
*/
const parseList = (value: string): string[] => {
const parseList = (value: string) => {
try {
const list = value.split(',').map((item) => item.trim()); // trim shouldn't be necessary but might help catch unexpected whitespace characters
return list;
return value.split(',').map((item) => item.trim()); // trim shouldn't be necessary but might help catch unexpected whitespace characters
} catch (e) {
exitWith(1, `Unrecognized input: ${value}`);
}
@ -55,7 +54,7 @@ const parseInteger = (value: string) => {
/**
* argParser: Parse a string as a URL object
*/
const parseURL = (value: string): URL => {
const parseURL = (value: string) => {
try {
const url = new URL(value);
if (!url.host) {

View File

@ -66,7 +66,11 @@ const createEntitiesWriteStream = (options: IEntitiesRestoreStreamOptions) => {
}
}
return typeof cType === 'object' ? cType?.uid : undefined;
if ('uid' in cType) {
return cType.uid;
}
return undefined;
};
try {

View File

@ -656,7 +656,9 @@ class Strapi implements StrapiI {
getModel(uid: Common.UID.ContentType): Schema.ContentType;
getModel(uid: Common.UID.Component): Schema.Component;
getModel<TUID extends Common.UID.Schema>(uid: TUID): Schema.ContentType | Schema.Component {
getModel<TUID extends Common.UID.Schema>(
uid: TUID
): Schema.ContentType | Schema.Component | undefined {
if (uid in this.contentTypes) {
return this.contentTypes[uid as Common.UID.ContentType];
}
@ -664,8 +666,6 @@ class Strapi implements StrapiI {
if (uid in this.components) {
return this.components[uid as Common.UID.Component];
}
throw new Error('Model not found');
}
/**

View File

@ -11,10 +11,9 @@ import { exitWith } from './helpers';
/**
* argParser: Parse a comma-delimited string as an array
*/
const parseList = (value: string): string[] => {
const parseList = (value: string) => {
try {
const list = value.split(',').map((item) => item.trim()); // trim shouldn't be necessary but might help catch unexpected whitespace characters
return list;
return value.split(',').map((item) => item.trim()); // trim shouldn't be necessary but might help catch unexpected whitespace characters
} catch (e) {
exitWith(1, `Unrecognized input: ${value}`);
}
@ -55,7 +54,7 @@ const parseInteger = (value: string) => {
/**
* argParser: Parse a string as a URL object
*/
const parseURL = (value: string): URL => {
const parseURL = (value: string) => {
try {
const url = new URL(value);
if (!url.host) {

View File

@ -9,7 +9,7 @@ import machineID from './machine-id';
try {
if (
process.env.npm_config_global === 'true' ||
JSON.parse(process.env.npm_config_argv ?? '').original.includes('global')
JSON.parse(process.env.npm_config_argv as any).original.includes('global')
) {
const event = 'didInstallStrapi';
fetch('https://analytics.strapi.io/api/v2/track', {

View File

@ -45,7 +45,7 @@ export type RouterConfig<TContentTypeUID extends Common.UID.ContentType> = {
// TODO Refactor when we have a controller registry
only?: string[];
except?: string[];
config: Utils.Expression.MatchFirst<
config?: Utils.Expression.MatchFirst<
[
Utils.Expression.Test<
Common.UID.IsCollectionType<TContentTypeUID>,

View File

@ -37,10 +37,6 @@ export interface Attribute<TKind extends Kind = Kind> {
* Options defined and used by the plugins
*/
pluginOptions?: object;
/**
* Options defined and used by Strapi core
*/
useJoinTable?: boolean;
}