1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

Refactor(#1391): don't check for OpenAPI version in snapshot tests (#2072)

* Refactor(#1391): don't check for OpenAPI version in snapshot tests

remove the version from the received specification. The version
_is_ a required field, but 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). That's why we
remove it.

* #1391: test that the "semver" property is present

* #1391: test that the openapi version is valid semver

* Chore(#1391): comment formatting
This commit is contained in:
Thomas Heartman 2022-09-19 11:07:26 +02:00 committed by GitHub
parent 54633500fd
commit 8869e6f04d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -3437,7 +3437,6 @@ exports[`should serve the OpenAPI spec 1`] = `
},
"info": {
"title": "Unleash API",
"version": "4.15.1",
},
"openapi": "3.0.3",
"paths": {

View File

@ -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')