From c14621a09a89ee5109e2d57863ba22f191737634 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Tue, 14 Feb 2023 11:25:13 +0100 Subject: [PATCH] fix: enabling more tests with strict schema validation (#3081) --- src/lib/openapi/spec/feature-events-schema.ts | 4 ++++ src/lib/openapi/spec/feature-schema.ts | 7 +++++++ .../openapi/spec/health-overview-schema.ts | 5 +++++ .../e2e/api/admin/constraints.e2e.test.ts | 10 +++++++-- src/test/e2e/api/admin/environment.test.ts | 13 ++++++++++-- src/test/e2e/api/admin/event.e2e.test.ts | 13 ++++++++++-- src/test/e2e/api/admin/feature.e2e.test.ts | 9 ++++++-- .../admin/project/project.health.e2e.test.ts | 10 +++++++-- .../api/admin/project/variants.e2e.test.ts | 13 ++++++++++-- src/test/e2e/api/admin/tags.e2e.test.ts | 10 +++++++-- .../__snapshots__/openapi.e2e.test.ts.snap | 21 +++++++++++++++++++ 11 files changed, 101 insertions(+), 14 deletions(-) diff --git a/src/lib/openapi/spec/feature-events-schema.ts b/src/lib/openapi/spec/feature-events-schema.ts index 912fd52fd7..1c412184f6 100644 --- a/src/lib/openapi/spec/feature-events-schema.ts +++ b/src/lib/openapi/spec/feature-events-schema.ts @@ -16,6 +16,10 @@ export const featureEventsSchema = { type: 'array', items: { $ref: eventSchema.$id }, }, + totalEvents: { + type: 'integer', + minimum: 0, + }, }, components: { schemas: { diff --git a/src/lib/openapi/spec/feature-schema.ts b/src/lib/openapi/spec/feature-schema.ts index 320ffafa39..62a9622f0c 100644 --- a/src/lib/openapi/spec/feature-schema.ts +++ b/src/lib/openapi/spec/feature-schema.ts @@ -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: { diff --git a/src/lib/openapi/spec/health-overview-schema.ts b/src/lib/openapi/spec/health-overview-schema.ts index e4d29c78f6..460e8fc743 100644 --- a/src/lib/openapi/spec/health-overview-schema.ts +++ b/src/lib/openapi/spec/health-overview-schema.ts @@ -23,6 +23,7 @@ export const healthOverviewSchema = { }, description: { type: 'string', + nullable: true, }, members: { type: 'number', @@ -50,6 +51,10 @@ export const healthOverviewSchema = { favorite: { type: 'boolean', }, + stats: { + $ref: '#/components/schemas/projectStatsSchema', + description: 'Project statistics', + }, }, components: { schemas: { diff --git a/src/test/e2e/api/admin/constraints.e2e.test.ts b/src/test/e2e/api/admin/constraints.e2e.test.ts index 11a30f17d5..009f1a65f0 100644 --- a/src/test/e2e/api/admin/constraints.e2e.test.ts +++ b/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; @@ -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 () => { diff --git a/src/test/e2e/api/admin/environment.test.ts b/src/test/e2e/api/admin/environment.test.ts index fb74aa85c5..7219c223d5 100644 --- a/src/test/e2e/api/admin/environment.test.ts +++ b/src/test/e2e/api/admin/environment.test.ts @@ -1,6 +1,9 @@ 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; @@ -8,7 +11,13 @@ 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 () => { diff --git a/src/test/e2e/api/admin/event.e2e.test.ts b/src/test/e2e/api/admin/event.e2e.test.ts index 055f599370..5ef6399059 100644 --- a/src/test/e2e/api/admin/event.e2e.test.ts +++ b/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'; @@ -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; }); diff --git a/src/test/e2e/api/admin/feature.e2e.test.ts b/src/test/e2e/api/admin/feature.e2e.test.ts index c31e73fd3f..3be5968684 100644 --- a/src/test/e2e/api/admin/feature.e2e.test.ts +++ b/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'; @@ -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, diff --git a/src/test/e2e/api/admin/project/project.health.e2e.test.ts b/src/test/e2e/api/admin/project/project.health.e2e.test.ts index f303329e12..bcd8085817 100644 --- a/src/test/e2e/api/admin/project/project.health.e2e.test.ts +++ b/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; @@ -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', diff --git a/src/test/e2e/api/admin/project/variants.e2e.test.ts b/src/test/e2e/api/admin/project/variants.e2e.test.ts index 115b536d95..0dcdeb29a6 100644 --- a/src/test/e2e/api/admin/project/variants.e2e.test.ts +++ b/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'; @@ -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', diff --git a/src/test/e2e/api/admin/tags.e2e.test.ts b/src/test/e2e/api/admin/tags.e2e.test.ts index adf122203d..272ef01be0 100644 --- a/src/test/e2e/api/admin/tags.e2e.test.ts +++ b/src/test/e2e/api/admin/tags.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; @@ -7,7 +7,13 @@ 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 () => { diff --git a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap index 73208757b6..e4f50411ad 100644 --- a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap +++ b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap @@ -1223,6 +1223,10 @@ exports[`should serve the OpenAPI spec 1`] = ` "toggleName": { "type": "string", }, + "totalEvents": { + "minimum": 0, + "type": "integer", + }, "version": { "type": "number", }, @@ -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": { @@ -1660,6 +1671,7 @@ exports[`should serve the OpenAPI spec 1`] = ` "additionalProperties": false, "properties": { "description": { + "nullable": true, "type": "string", }, "environments": { @@ -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, @@ -1708,6 +1724,7 @@ exports[`should serve the OpenAPI spec 1`] = ` "type": "number", }, "description": { + "nullable": true, "type": "string", }, "environments": { @@ -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,