Skip to content

Commit

Permalink
fix: enabling more tests with strict schema validation (#3081)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Feb 14, 2023
1 parent c78b2d8 commit c14621a
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/lib/openapi/spec/feature-events-schema.ts
Expand Up @@ -16,6 +16,10 @@ export const featureEventsSchema = {
type: 'array',
items: { $ref: eventSchema.$id },
},
totalEvents: {
type: 'integer',
minimum: 0,
},
},
components: {
schemas: {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/openapi/spec/feature-schema.ts
Expand Up @@ -97,6 +97,13 @@ export const featureSchema = {
},
description: 'The list of feature variants',
},
strategies: {
type: 'array',
items: {
type: 'object',
},
description: 'This is a legacy field that will be deprecated',
},
tags: {
type: 'array',
items: {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/openapi/spec/health-overview-schema.ts
Expand Up @@ -23,6 +23,7 @@ export const healthOverviewSchema = {
},
description: {
type: 'string',
nullable: true,
},
members: {
type: 'number',
Expand Down Expand Up @@ -50,6 +51,10 @@ export const healthOverviewSchema = {
favorite: {
type: 'boolean',
},
stats: {
$ref: '#/components/schemas/projectStatsSchema',
description: 'Project statistics',
},
},
components: {
schemas: {
Expand Down
10 changes: 8 additions & 2 deletions src/test/e2e/api/admin/constraints.e2e.test.ts
@@ -1,6 +1,6 @@
import dbInit from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
import { setupApp } from '../../helpers/test-helper';
import { setupAppWithCustomConfig } from '../../helpers/test-helper';

let app;
let db;
Expand All @@ -9,7 +9,13 @@ const PATH = '/api/admin/constraints/validate';

beforeAll(async () => {
db = await dbInit('constraints', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});
});

afterAll(async () => {
Expand Down
13 changes: 11 additions & 2 deletions src/test/e2e/api/admin/environment.test.ts
@@ -1,14 +1,23 @@
import dbInit, { ITestDb } from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
import { IUnleashTest, setupApp } from '../../helpers/test-helper';
import {
IUnleashTest,
setupAppWithCustomConfig,
} from '../../helpers/test-helper';
import { DEFAULT_ENV } from '../../../../lib/util/constants';

let app: IUnleashTest;
let db: ITestDb;

beforeAll(async () => {
db = await dbInit('environment_api_serial', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});
});

afterAll(async () => {
Expand Down
13 changes: 11 additions & 2 deletions src/test/e2e/api/admin/event.e2e.test.ts
@@ -1,4 +1,7 @@
import { IUnleashTest, setupApp } from '../../helpers/test-helper';
import {
IUnleashTest,
setupAppWithCustomConfig,
} from '../../helpers/test-helper';
import dbInit, { ITestDb } from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
import { FEATURE_CREATED, IBaseEvent } from '../../../../lib/types/events';
Expand All @@ -11,7 +14,13 @@ let eventStore: IEventStore;

beforeAll(async () => {
db = await dbInit('event_api_serial', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});
eventStore = db.stores.eventStore;
});

Expand Down
9 changes: 7 additions & 2 deletions src/test/e2e/api/admin/feature.e2e.test.ts
@@ -1,7 +1,6 @@
import dbInit, { ITestDb } from '../../helpers/database-init';
import {
IUnleashTest,
setupApp,
setupAppWithCustomConfig,
} from '../../helpers/test-helper';
import getLogger from '../../../fixtures/no-logger';
Expand All @@ -24,7 +23,13 @@ const defaultStrategy = {

beforeAll(async () => {
db = await dbInit('feature_api_serial', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});

const createToggle = async (
toggle: FeatureToggleDTO,
Expand Down
10 changes: 8 additions & 2 deletions src/test/e2e/api/admin/project/project.health.e2e.test.ts
@@ -1,5 +1,5 @@
import dbInit from '../../../helpers/database-init';
import { setupApp } from '../../../helpers/test-helper';
import { setupAppWithCustomConfig } from '../../../helpers/test-helper';
import getLogger from '../../../../fixtures/no-logger';

let app;
Expand All @@ -8,7 +8,13 @@ let user;

beforeAll(async () => {
db = await dbInit('project_health_api_serial', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});
user = await db.stores.userStore.insert({
name: 'Some Name',
email: 'test@getunleash.io',
Expand Down
13 changes: 11 additions & 2 deletions src/test/e2e/api/admin/project/variants.e2e.test.ts
@@ -1,4 +1,7 @@
import { IUnleashTest, setupApp } from '../../../helpers/test-helper';
import {
IUnleashTest,
setupAppWithCustomConfig,
} from '../../../helpers/test-helper';
import dbInit, { ITestDb } from '../../../helpers/database-init';
import getLogger from '../../../../fixtures/no-logger';
import * as jsonpatch from 'fast-json-patch';
Expand All @@ -9,7 +12,13 @@ let db: ITestDb;

beforeAll(async () => {
db = await dbInit('project_feature_variants_api_serial', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});
await db.stores.environmentStore.create({
name: 'development',
type: 'development',
Expand Down
10 changes: 8 additions & 2 deletions src/test/e2e/api/admin/tags.e2e.test.ts
@@ -1,13 +1,19 @@
import dbInit from '../../helpers/database-init';
import { setupApp } from '../../helpers/test-helper';
import { setupAppWithCustomConfig } from '../../helpers/test-helper';
import getLogger from '../../../fixtures/no-logger';

let app;
let db;

beforeAll(async () => {
db = await dbInit('tag_api_serial', getLogger);
app = await setupApp(db.stores);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});
});

afterAll(async () => {
Expand Down
21 changes: 21 additions & 0 deletions src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap
Expand Up @@ -1223,6 +1223,10 @@ exports[`should serve the OpenAPI spec 1`] = `
"toggleName": {
"type": "string",
},
"totalEvents": {
"minimum": 0,
"type": "integer",
},
"version": {
"type": "number",
},
Expand Down Expand Up @@ -1323,6 +1327,13 @@ exports[`should serve the OpenAPI spec 1`] = `
"example": false,
"type": "boolean",
},
"strategies": {
"description": "This is a legacy field that will be deprecated",
"items": {
"type": "object",
},
"type": "array",
},
"tags": {
"description": "The list of feature tags",
"items": {
Expand Down Expand Up @@ -1660,6 +1671,7 @@ exports[`should serve the OpenAPI spec 1`] = `
"additionalProperties": false,
"properties": {
"description": {
"nullable": true,
"type": "string",
},
"environments": {
Expand All @@ -1686,6 +1698,10 @@ exports[`should serve the OpenAPI spec 1`] = `
"name": {
"type": "string",
},
"stats": {
"$ref": "#/components/schemas/projectStatsSchema",
"description": "Project statistics",
},
"updatedAt": {
"format": "date-time",
"nullable": true,
Expand All @@ -1708,6 +1724,7 @@ exports[`should serve the OpenAPI spec 1`] = `
"type": "number",
},
"description": {
"nullable": true,
"type": "string",
},
"environments": {
Expand Down Expand Up @@ -1740,6 +1757,10 @@ exports[`should serve the OpenAPI spec 1`] = `
"staleCount": {
"type": "number",
},
"stats": {
"$ref": "#/components/schemas/projectStatsSchema",
"description": "Project statistics",
},
"updatedAt": {
"format": "date-time",
"nullable": true,
Expand Down

0 comments on commit c14621a

Please sign in to comment.