From 6ab850318de7b92a3fc77c88520883f6b9836fad Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Fri, 16 Sep 2022 13:17:54 -0400 Subject: [PATCH 1/9] Location url was incorrect Signed-off-by: Taras --- packages/catalog-client/src/CatalogClient.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/catalog-client/src/CatalogClient.test.ts b/packages/catalog-client/src/CatalogClient.test.ts index 6c9c68efa2..5a344f49a3 100644 --- a/packages/catalog-client/src/CatalogClient.test.ts +++ b/packages/catalog-client/src/CatalogClient.test.ts @@ -322,7 +322,7 @@ describe('CatalogClient', () => { name: '', }, }, - 'http://example.com', + 'url:http://example.com', ), ).toMatchObject({ valid: false, @@ -350,7 +350,7 @@ describe('CatalogClient', () => { name: 'good', }, }, - 'http://example.com', + 'url:http://example.com', ), ).toMatchObject({ valid: true, @@ -373,7 +373,7 @@ describe('CatalogClient', () => { name: 'good', }, }, - 'http://example.com', + 'url:http://example.com', ), ).rejects.toThrow(/Request failed with 500 Error/); }); From 312e61a45141ccc7fc24ebebe5d34cc400feed53 Mon Sep 17 00:00:00 2001 From: Taras Date: Fri, 23 Sep 2022 10:51:08 -0400 Subject: [PATCH 2/9] Rename location to locationRef Signed-off-by: Taras --- packages/catalog-client/api-report.md | 4 ++-- packages/catalog-client/src/CatalogClient.ts | 4 ++-- packages/catalog-client/src/types/api.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/catalog-client/api-report.md b/packages/catalog-client/api-report.md index 0ad77ce39c..85fc389af7 100644 --- a/packages/catalog-client/api-report.md +++ b/packages/catalog-client/api-report.md @@ -68,7 +68,7 @@ export interface CatalogApi { ): Promise; validateEntity( entity: Entity, - location: string, + locationRef: string, options?: CatalogRequestOptions, ): Promise; } @@ -130,7 +130,7 @@ export class CatalogClient implements CatalogApi { ): Promise; validateEntity( entity: Entity, - location: string, + locationRef: string, options?: CatalogRequestOptions, ): Promise; } diff --git a/packages/catalog-client/src/CatalogClient.ts b/packages/catalog-client/src/CatalogClient.ts index f2b4186bfb..d67392d80d 100644 --- a/packages/catalog-client/src/CatalogClient.ts +++ b/packages/catalog-client/src/CatalogClient.ts @@ -359,7 +359,7 @@ export class CatalogClient implements CatalogApi { */ async validateEntity( entity: Entity, - location: string, + locationRef: string, options?: CatalogRequestOptions, ): Promise { const response = await this.fetchApi.fetch( @@ -370,7 +370,7 @@ export class CatalogClient implements CatalogApi { ...(options?.token && { Authorization: `Bearer ${options?.token}` }), }, method: 'POST', - body: JSON.stringify({ entity, location }), + body: JSON.stringify({ entity, location: locationRef }), }, ); diff --git a/packages/catalog-client/src/types/api.ts b/packages/catalog-client/src/types/api.ts index f483c3454c..d3d02022f3 100644 --- a/packages/catalog-client/src/types/api.ts +++ b/packages/catalog-client/src/types/api.ts @@ -405,11 +405,11 @@ export interface CatalogApi { * Validate entity and its location. * * @param entity - Entity to validate - * @param location - URL location of the entity + * @param locationRef - Location ref in format `url:http://example.com/file` */ validateEntity( entity: Entity, - location: string, + locationRef: string, options?: CatalogRequestOptions, ): Promise; } From 4f2ac624b4a69cab1097a0933cd2e7ab1bdc65bc Mon Sep 17 00:00:00 2001 From: Taras Date: Fri, 23 Sep 2022 10:59:20 -0400 Subject: [PATCH 3/9] Added changeset for renamed argument Signed-off-by: Taras --- .changeset/plenty-kids-fetch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/plenty-kids-fetch.md diff --git a/.changeset/plenty-kids-fetch.md b/.changeset/plenty-kids-fetch.md new file mode 100644 index 0000000000..6a31b4db20 --- /dev/null +++ b/.changeset/plenty-kids-fetch.md @@ -0,0 +1,5 @@ +--- +'@backstage/catalog-client': patch +--- + +Renamed argument in `validateEntity` from `location` to `locationRef` From 2cd4b2e55862d9a6ab411ec8ac598511ce5e7a6c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Sep 2022 11:15:25 +0000 Subject: [PATCH 4/9] Update dependency @swc/core to v1.3.3 Signed-off-by: Renovate Bot --- storybook/yarn.lock | 110 ++++++++++++++++++++++---------------------- yarn.lock | 110 ++++++++++++++++++++++---------------------- 2 files changed, 110 insertions(+), 110 deletions(-) diff --git a/storybook/yarn.lock b/storybook/yarn.lock index 4a5d57c5b2..1597d0728c 100644 --- a/storybook/yarn.lock +++ b/storybook/yarn.lock @@ -2977,126 +2977,126 @@ __metadata: languageName: node linkType: hard -"@swc/core-android-arm-eabi@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-android-arm-eabi@npm:1.3.2" +"@swc/core-android-arm-eabi@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-android-arm-eabi@npm:1.3.3" dependencies: "@swc/wasm": 1.2.122 conditions: os=android & cpu=arm languageName: node linkType: hard -"@swc/core-android-arm64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-android-arm64@npm:1.3.2" +"@swc/core-android-arm64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-android-arm64@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=android & cpu=arm64 languageName: node linkType: hard -"@swc/core-darwin-arm64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-darwin-arm64@npm:1.3.2" +"@swc/core-darwin-arm64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-darwin-arm64@npm:1.3.3" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@swc/core-darwin-x64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-darwin-x64@npm:1.3.2" +"@swc/core-darwin-x64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-darwin-x64@npm:1.3.3" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@swc/core-freebsd-x64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-freebsd-x64@npm:1.3.2" +"@swc/core-freebsd-x64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-freebsd-x64@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=freebsd & cpu=x64 languageName: node linkType: hard -"@swc/core-linux-arm-gnueabihf@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-arm-gnueabihf@npm:1.3.2" +"@swc/core-linux-arm-gnueabihf@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-arm-gnueabihf@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=linux & cpu=arm languageName: node linkType: hard -"@swc/core-linux-arm64-gnu@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-arm64-gnu@npm:1.3.2" +"@swc/core-linux-arm64-gnu@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-arm64-gnu@npm:1.3.3" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@swc/core-linux-arm64-musl@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-arm64-musl@npm:1.3.2" +"@swc/core-linux-arm64-musl@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-arm64-musl@npm:1.3.3" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@swc/core-linux-x64-gnu@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-x64-gnu@npm:1.3.2" +"@swc/core-linux-x64-gnu@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-x64-gnu@npm:1.3.3" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@swc/core-linux-x64-musl@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-x64-musl@npm:1.3.2" +"@swc/core-linux-x64-musl@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-x64-musl@npm:1.3.3" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@swc/core-win32-arm64-msvc@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-win32-arm64-msvc@npm:1.3.2" +"@swc/core-win32-arm64-msvc@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-win32-arm64-msvc@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@swc/core-win32-ia32-msvc@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-win32-ia32-msvc@npm:1.3.2" +"@swc/core-win32-ia32-msvc@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-win32-ia32-msvc@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=win32 & cpu=ia32 languageName: node linkType: hard -"@swc/core-win32-x64-msvc@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-win32-x64-msvc@npm:1.3.2" +"@swc/core-win32-x64-msvc@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-win32-x64-msvc@npm:1.3.3" conditions: os=win32 & cpu=x64 languageName: node linkType: hard "@swc/core@npm:^1.2.239": - version: 1.3.2 - resolution: "@swc/core@npm:1.3.2" + version: 1.3.3 + resolution: "@swc/core@npm:1.3.3" dependencies: - "@swc/core-android-arm-eabi": 1.3.2 - "@swc/core-android-arm64": 1.3.2 - "@swc/core-darwin-arm64": 1.3.2 - "@swc/core-darwin-x64": 1.3.2 - "@swc/core-freebsd-x64": 1.3.2 - "@swc/core-linux-arm-gnueabihf": 1.3.2 - "@swc/core-linux-arm64-gnu": 1.3.2 - "@swc/core-linux-arm64-musl": 1.3.2 - "@swc/core-linux-x64-gnu": 1.3.2 - "@swc/core-linux-x64-musl": 1.3.2 - "@swc/core-win32-arm64-msvc": 1.3.2 - "@swc/core-win32-ia32-msvc": 1.3.2 - "@swc/core-win32-x64-msvc": 1.3.2 + "@swc/core-android-arm-eabi": 1.3.3 + "@swc/core-android-arm64": 1.3.3 + "@swc/core-darwin-arm64": 1.3.3 + "@swc/core-darwin-x64": 1.3.3 + "@swc/core-freebsd-x64": 1.3.3 + "@swc/core-linux-arm-gnueabihf": 1.3.3 + "@swc/core-linux-arm64-gnu": 1.3.3 + "@swc/core-linux-arm64-musl": 1.3.3 + "@swc/core-linux-x64-gnu": 1.3.3 + "@swc/core-linux-x64-musl": 1.3.3 + "@swc/core-win32-arm64-msvc": 1.3.3 + "@swc/core-win32-ia32-msvc": 1.3.3 + "@swc/core-win32-x64-msvc": 1.3.3 dependenciesMeta: "@swc/core-android-arm-eabi": optional: true @@ -3126,7 +3126,7 @@ __metadata: optional: true bin: swcx: run_swcx.js - checksum: c2c83d0e6b4c56d65fb3723aa0be5e777823a6efe5b12702d4d44827a6c6dd8fac3c5dec7ff45222c7b22b4084bffc846f8497d697e61a1706817977256a65dc + checksum: bead8463cd7c11e2cd87d3835045e4a245e755409e912a40c575026a0475cc0010fa6ef48936ea5f7e62c84cdc63c21a83d61755813f2ba9b565d397fad7c5f5 languageName: node linkType: hard diff --git a/yarn.lock b/yarn.lock index ab32864850..39c676a57e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12184,126 +12184,126 @@ __metadata: languageName: node linkType: hard -"@swc/core-android-arm-eabi@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-android-arm-eabi@npm:1.3.2" +"@swc/core-android-arm-eabi@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-android-arm-eabi@npm:1.3.3" dependencies: "@swc/wasm": 1.2.122 conditions: os=android & cpu=arm languageName: node linkType: hard -"@swc/core-android-arm64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-android-arm64@npm:1.3.2" +"@swc/core-android-arm64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-android-arm64@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=android & cpu=arm64 languageName: node linkType: hard -"@swc/core-darwin-arm64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-darwin-arm64@npm:1.3.2" +"@swc/core-darwin-arm64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-darwin-arm64@npm:1.3.3" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@swc/core-darwin-x64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-darwin-x64@npm:1.3.2" +"@swc/core-darwin-x64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-darwin-x64@npm:1.3.3" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@swc/core-freebsd-x64@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-freebsd-x64@npm:1.3.2" +"@swc/core-freebsd-x64@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-freebsd-x64@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=freebsd & cpu=x64 languageName: node linkType: hard -"@swc/core-linux-arm-gnueabihf@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-arm-gnueabihf@npm:1.3.2" +"@swc/core-linux-arm-gnueabihf@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-arm-gnueabihf@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=linux & cpu=arm languageName: node linkType: hard -"@swc/core-linux-arm64-gnu@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-arm64-gnu@npm:1.3.2" +"@swc/core-linux-arm64-gnu@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-arm64-gnu@npm:1.3.3" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@swc/core-linux-arm64-musl@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-arm64-musl@npm:1.3.2" +"@swc/core-linux-arm64-musl@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-arm64-musl@npm:1.3.3" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@swc/core-linux-x64-gnu@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-x64-gnu@npm:1.3.2" +"@swc/core-linux-x64-gnu@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-x64-gnu@npm:1.3.3" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@swc/core-linux-x64-musl@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-linux-x64-musl@npm:1.3.2" +"@swc/core-linux-x64-musl@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-linux-x64-musl@npm:1.3.3" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@swc/core-win32-arm64-msvc@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-win32-arm64-msvc@npm:1.3.2" +"@swc/core-win32-arm64-msvc@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-win32-arm64-msvc@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@swc/core-win32-ia32-msvc@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-win32-ia32-msvc@npm:1.3.2" +"@swc/core-win32-ia32-msvc@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-win32-ia32-msvc@npm:1.3.3" dependencies: "@swc/wasm": 1.2.130 conditions: os=win32 & cpu=ia32 languageName: node linkType: hard -"@swc/core-win32-x64-msvc@npm:1.3.2": - version: 1.3.2 - resolution: "@swc/core-win32-x64-msvc@npm:1.3.2" +"@swc/core-win32-x64-msvc@npm:1.3.3": + version: 1.3.3 + resolution: "@swc/core-win32-x64-msvc@npm:1.3.3" conditions: os=win32 & cpu=x64 languageName: node linkType: hard "@swc/core@npm:^1.2.239": - version: 1.3.2 - resolution: "@swc/core@npm:1.3.2" + version: 1.3.3 + resolution: "@swc/core@npm:1.3.3" dependencies: - "@swc/core-android-arm-eabi": 1.3.2 - "@swc/core-android-arm64": 1.3.2 - "@swc/core-darwin-arm64": 1.3.2 - "@swc/core-darwin-x64": 1.3.2 - "@swc/core-freebsd-x64": 1.3.2 - "@swc/core-linux-arm-gnueabihf": 1.3.2 - "@swc/core-linux-arm64-gnu": 1.3.2 - "@swc/core-linux-arm64-musl": 1.3.2 - "@swc/core-linux-x64-gnu": 1.3.2 - "@swc/core-linux-x64-musl": 1.3.2 - "@swc/core-win32-arm64-msvc": 1.3.2 - "@swc/core-win32-ia32-msvc": 1.3.2 - "@swc/core-win32-x64-msvc": 1.3.2 + "@swc/core-android-arm-eabi": 1.3.3 + "@swc/core-android-arm64": 1.3.3 + "@swc/core-darwin-arm64": 1.3.3 + "@swc/core-darwin-x64": 1.3.3 + "@swc/core-freebsd-x64": 1.3.3 + "@swc/core-linux-arm-gnueabihf": 1.3.3 + "@swc/core-linux-arm64-gnu": 1.3.3 + "@swc/core-linux-arm64-musl": 1.3.3 + "@swc/core-linux-x64-gnu": 1.3.3 + "@swc/core-linux-x64-musl": 1.3.3 + "@swc/core-win32-arm64-msvc": 1.3.3 + "@swc/core-win32-ia32-msvc": 1.3.3 + "@swc/core-win32-x64-msvc": 1.3.3 dependenciesMeta: "@swc/core-android-arm-eabi": optional: true @@ -12333,7 +12333,7 @@ __metadata: optional: true bin: swcx: run_swcx.js - checksum: c2c83d0e6b4c56d65fb3723aa0be5e777823a6efe5b12702d4d44827a6c6dd8fac3c5dec7ff45222c7b22b4084bffc846f8497d697e61a1706817977256a65dc + checksum: bead8463cd7c11e2cd87d3835045e4a245e755409e912a40c575026a0475cc0010fa6ef48936ea5f7e62c84cdc63c21a83d61755813f2ba9b565d397fad7c5f5 languageName: node linkType: hard From 6e05d57fdf3fcb92a8b6aac2ae63c81f7a11c554 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:04:44 +0000 Subject: [PATCH 5/9] chore(deps): update dependency @types/tar to v6.1.3 Signed-off-by: Renovate Bot --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 7776d00e77..57a331f80f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14598,12 +14598,12 @@ __metadata: linkType: hard "@types/tar@npm:^6.1.1": - version: 6.1.2 - resolution: "@types/tar@npm:6.1.2" + version: 6.1.3 + resolution: "@types/tar@npm:6.1.3" dependencies: "@types/node": "*" minipass: ^3.3.5 - checksum: 57e625e2db29e3b9c6d8d06774758cf6e4caa2096f4144f7c0fdb2760e1150146d2a86f0eb80b4d2e1ba0ecf07f06303775054c4f4d22bea5d51e8b54cdd0fd8 + checksum: 3a221f74adfcef8555b9c4cc951907dfd567630744ffe5211da1b44caf2a4c3b02297b73c9fb02d171e93a7a7c74fb15c1826e3f0438f0e5e8f4c790db59ddcf languageName: node linkType: hard From f7cbfb97edd8ea5d01961a538b36aa585869cb98 Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Wed, 28 Sep 2022 11:17:55 +0200 Subject: [PATCH 6/9] Modify router endpoint to handle singular and collections of request params similarly. Signed-off-by: Jussi Hallila --- .changeset/twelve-melons-notice.md | 5 + .../src/service/router.test.ts | 129 +++++++++++------- .../src/service/router.ts | 19 ++- 3 files changed, 104 insertions(+), 49 deletions(-) create mode 100644 .changeset/twelve-melons-notice.md diff --git a/.changeset/twelve-melons-notice.md b/.changeset/twelve-melons-notice.md new file mode 100644 index 0000000000..621d6325a7 --- /dev/null +++ b/.changeset/twelve-melons-notice.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-tech-insights-backend': patch +--- + +Modify router endpoint to handle singular and collections of request params similarly. diff --git a/plugins/tech-insights-backend/src/service/router.test.ts b/plugins/tech-insights-backend/src/service/router.test.ts index 8513973598..6935338a56 100644 --- a/plugins/tech-insights-backend/src/service/router.test.ts +++ b/plugins/tech-insights-backend/src/service/router.test.ts @@ -87,59 +87,94 @@ describe('Tech Insights router tests', () => { app = express().use(router); }); - - it('should be able to retrieve latest schemas', async () => { - await request(app).get('/fact-schemas').expect(200); - expect(latestSchemasMock).toHaveBeenCalled(); + describe('/fact-schemas', () => { + it('should be able to retrieve latest schemas', async () => { + await request(app).get('/fact-schemas').expect(200); + expect(latestSchemasMock).toHaveBeenCalled(); + }); }); - it('should not contain check endpoints when checker not present', async () => { - await request(app).get('/checks').expect(404); - await request(app).post('/checks/a/a/a').expect(404); + describe('/checks', () => { + it('should not contain check endpoints when checker not present', async () => { + await request(app).get('/checks').expect(404); + await request(app).post('/checks/a/a/a').expect(404); + }); }); - it('should be able to parse id request params for fact retrieval', async () => { - await request(app) - .get('/facts/latest') - .query({ - entity: 'a:a/a', - ids: ['firstId', 'secondId'], - }) - .expect(200); - expect(latestFactsByIdsMock).toHaveBeenCalledWith( - ['firstId', 'secondId'], - 'a:a/a', - ); + describe('/facts/latest', () => { + it('should be able to parse id request params for fact retrieval', async () => { + await request(app) + .get('/facts/latest') + .query({ + entity: 'a:a/a', + ids: ['firstId', 'secondId'], + }) + .expect(200); + expect(latestFactsByIdsMock).toHaveBeenCalledWith( + ['firstId', 'secondId'], + 'a:a/a', + ); + }); + it('should handle singular ids in query params correctly', async () => { + await request(app) + .get('/facts/latest') + .query({ + entity: 'a:a/a', + ids: ['secondId'], + }) + .expect(200); + expect(latestFactsByIdsMock).toHaveBeenCalledWith(['secondId'], 'a:a/a'); + }); }); - it('should be able to parse datetime request params for fact retrieval', async () => { - await request(app) - .get('/facts/range') - .query({ - entity: 'a:a/a', - ids: ['firstId', 'secondId'], - startDatetime: '2021-12-12T12:12:12', - endDatetime: '2022-11-11T11:11:11', - }) - .expect(200); - expect(factsBetweenTimestampsByIdsMock).toHaveBeenCalledWith( - ['firstId', 'secondId'], - 'a:a/a', - DateTime.fromISO('2021-12-12T12:12:12.000+00:00'), - DateTime.fromISO('2022-11-11T11:11:11.000+00:00'), - ); - }); + describe('/facts/range', () => { + it('should be able to parse datetime request params for fact retrieval', async () => { + await request(app) + .get('/facts/range') + .query({ + entity: 'a:a/a', + ids: ['firstId', 'secondId'], + startDatetime: '2021-12-12T12:12:12', + endDatetime: '2022-11-11T11:11:11', + }) + .expect(200); + expect(factsBetweenTimestampsByIdsMock).toHaveBeenCalledWith( + ['firstId', 'secondId'], + 'a:a/a', + DateTime.fromISO('2021-12-12T12:12:12.000+00:00'), + DateTime.fromISO('2022-11-11T11:11:11.000+00:00'), + ); + }); - it('should respond gracefully on parsing errors', async () => { - await request(app) - .get('/facts/range') - .query({ - entity: 'a:a/a', - ids: ['firstId', 'secondId'], - startDatetime: '2021-12-1222T12:12:12', - endDatetime: '2022-1122-11T11:11:11', - }) - .expect(422); - expect(latestFactsByIdsMock).toHaveBeenCalledTimes(0); + it('should respond gracefully on parsing errors', async () => { + await request(app) + .get('/facts/range') + .query({ + entity: 'a:a/a', + ids: ['firstId', 'secondId'], + startDatetime: '2021-12-1222T12:12:12', + endDatetime: '2022-1122-11T11:11:11', + }) + .expect(422); + expect(latestFactsByIdsMock).toHaveBeenCalledTimes(0); + }); + + it('should handle singular ids in query params correctly', async () => { + await request(app) + .get('/facts/range') + .query({ + entity: 'a:a/a', + ids: ['firstId'], + startDatetime: '2021-12-12T12:12:12', + endDatetime: '2022-11-11T11:11:11', + }) + .expect(200); + expect(factsBetweenTimestampsByIdsMock).toHaveBeenCalledWith( + ['firstId'], + 'a:a/a', + DateTime.fromISO('2021-12-12T12:12:12.000+00:00'), + DateTime.fromISO('2022-11-11T11:11:11.000+00:00'), + ); + }); }); }); diff --git a/plugins/tech-insights-backend/src/service/router.ts b/plugins/tech-insights-backend/src/service/router.ts index 4b93bf4d60..a7f48bc3a2 100644 --- a/plugins/tech-insights-backend/src/service/router.ts +++ b/plugins/tech-insights-backend/src/service/router.ts @@ -132,7 +132,15 @@ export async function createRouter< router.get('/facts/latest', async (req, res) => { const { entity } = req.query; const { namespace, kind, name } = parseEntityRef(entity as string); - const ids = req.query.ids as string[]; + + if (!req.query.ids) { + return res + .status(422) + .send({ error: 'Failed to parse ids from request' }); + } + const ids = Array.isArray(req.query.ids) + ? (req.query.ids as string[]) + : ([req.query.ids] as string[]); return res.send( await techInsightsStore.getLatestFactsByIds( ids, @@ -148,7 +156,14 @@ export async function createRouter< const { entity } = req.query; const { namespace, kind, name } = parseEntityRef(entity as string); - const ids = req.query.ids as string[]; + if (!req.query.ids) { + return res + .status(422) + .send({ error: 'Failed to parse ids from request' }); + } + const ids = Array.isArray(req.query.ids) + ? (req.query.ids as string[]) + : ([req.query.ids] as string[]); const startDatetime = DateTime.fromISO(req.query.startDatetime as string); const endDatetime = DateTime.fromISO(req.query.endDatetime as string); if (!startDatetime.isValid || !endDatetime.isValid) { From 74d13e677dbf8cbe75d6bf1ac3d344e89ee87e28 Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Wed, 28 Sep 2022 11:25:07 +0200 Subject: [PATCH 7/9] Fix changeset to read English instead of nerd English. Signed-off-by: Jussi Hallila --- .changeset/twelve-melons-notice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/twelve-melons-notice.md b/.changeset/twelve-melons-notice.md index 621d6325a7..4a91642426 100644 --- a/.changeset/twelve-melons-notice.md +++ b/.changeset/twelve-melons-notice.md @@ -2,4 +2,4 @@ '@backstage/plugin-tech-insights-backend': patch --- -Modify router endpoint to handle singular and collections of request params similarly. +Modify router endpoint to handle singular and collections of request parameters similarly. From 91d9311ce38656c21d601a5a3671bacce938895c Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Wed, 28 Sep 2022 12:02:15 +0200 Subject: [PATCH 8/9] Change to a simple logic. Signed-off-by: Jussi Hallila --- plugins/tech-insights-backend/src/service/router.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plugins/tech-insights-backend/src/service/router.ts b/plugins/tech-insights-backend/src/service/router.ts index a7f48bc3a2..0df7080db5 100644 --- a/plugins/tech-insights-backend/src/service/router.ts +++ b/plugins/tech-insights-backend/src/service/router.ts @@ -138,9 +138,7 @@ export async function createRouter< .status(422) .send({ error: 'Failed to parse ids from request' }); } - const ids = Array.isArray(req.query.ids) - ? (req.query.ids as string[]) - : ([req.query.ids] as string[]); + const ids = [req.query.ids].flat() as string[]; return res.send( await techInsightsStore.getLatestFactsByIds( ids, @@ -161,9 +159,7 @@ export async function createRouter< .status(422) .send({ error: 'Failed to parse ids from request' }); } - const ids = Array.isArray(req.query.ids) - ? (req.query.ids as string[]) - : ([req.query.ids] as string[]); + const ids = [req.query.ids].flat() as string[]; const startDatetime = DateTime.fromISO(req.query.startDatetime as string); const endDatetime = DateTime.fromISO(req.query.endDatetime as string); if (!startDatetime.isValid || !endDatetime.isValid) { From 3cf87c1d114e08fb1233d2466bfbf36e023f8565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Wed, 28 Sep 2022 12:03:43 +0200 Subject: [PATCH 9/9] forgot a slash ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- plugins/user-settings/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/user-settings/README.md b/plugins/user-settings/README.md index b240c2bbd3..ce07d76257 100644 --- a/plugins/user-settings/README.md +++ b/plugins/user-settings/README.md @@ -33,7 +33,7 @@ import { UserSettingsPage } from '@backstage/plugin-user-settings'; const AppRoutes = () => ( - }> + } /> ); ```