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 4027c1f8b4..7d5ae3830d 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 @@ -3437,7 +3437,6 @@ exports[`should serve the OpenAPI spec 1`] = ` }, "info": { "title": "Unleash API", - "version": "4.15.1", }, "openapi": "3.0.3", "paths": { diff --git a/src/test/e2e/api/openapi/openapi.e2e.test.ts b/src/test/e2e/api/openapi/openapi.e2e.test.ts index 97391f4d65..39400f6b5a 100644 --- a/src/test/e2e/api/openapi/openapi.e2e.test.ts +++ b/src/test/e2e/api/openapi/openapi.e2e.test.ts @@ -2,6 +2,7 @@ import { setupApp } from '../../helpers/test-helper'; import dbInit from '../../helpers/database-init'; import getLogger from '../../../fixtures/no-logger'; import SwaggerParser from '@apidevtools/swagger-parser'; +import semver from 'semver'; let app; let db; @@ -30,12 +31,32 @@ test('should serve the OpenAPI spec', async () => { .expect('Content-Type', /json/) .expect(200) .expect((res) => { + // Don't use the version field in snapshot tests. Having the version + // listed in automated testing causes issues when trying to deploy + // new versions of the API (due to mismatch between new tag versions etc). + delete res.body.info.version; + // This test will fail whenever there's a change to the API spec. // If the change is intended, update the snapshot with `jest -u`. expect(res.body).toMatchSnapshot(); }); }); +test('should serve the OpenAPI spec with a `version` property', async () => { + return app.request + .get('/docs/openapi.json') + .expect('Content-Type', /json/) + .expect(200) + .expect((res) => { + const { version } = res.body.info; + // ensure there's no whitespace or leading `v` + expect(semver.clean(version)).toStrictEqual(version); + + // ensure the version listed is valid semver + expect(semver.parse(version, { loose: false })).toBeTruthy(); + }); +}); + test('the generated OpenAPI spec is valid', async () => { const { body } = await app.request .get('/docs/openapi.json')