From 5e695b5a3205621119392cae2fc0899f208509e6 Mon Sep 17 00:00:00 2001 From: Guillaume Bourdat Date: Thu, 9 Jan 2025 18:43:01 +0100 Subject: [PATCH] #129 : fix api test --- .../dbApi/kysely/createPgSoftwareRepository.ts | 15 +++++++++++++-- .../dbApi/kysely/pgDbApi.integration.test.ts | 1 - api/src/core/usecases/readWriteSillData/types.ts | 3 +-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/api/src/core/adapters/dbApi/kysely/createPgSoftwareRepository.ts b/api/src/core/adapters/dbApi/kysely/createPgSoftwareRepository.ts index 34ca16fe..77d2d4db 100644 --- a/api/src/core/adapters/dbApi/kysely/createPgSoftwareRepository.ts +++ b/api/src/core/adapters/dbApi/kysely/createPgSoftwareRepository.ts @@ -193,7 +193,8 @@ export const createPgSoftwareRepository = (db: Kysely): SoftwareReposi programmingLanguages: softwareExternalData?.programmingLanguages ?? [], applicationCategories: software.categories.concat( softwareExternalData?.applicationCategories ?? [] - ) + ), + categories: undefined // merged in applicationCategories, set to undefined to remove it }); }), getById: getBySoftwareId, @@ -290,6 +291,7 @@ export const createPgSoftwareRepository = (db: Kysely): SoftwareReposi applicationCategories: software.categories.concat( softwareExternalData?.applicationCategories ?? [] ), + categories: undefined, // merged in applicationCategories, set to undefined to remove it programmingLanguages: softwareExternalData?.programmingLanguages ?? [] }); } @@ -511,6 +513,12 @@ const getUserAndReferentCountByOrganizationBySoftwareId = async ( ); }; +const filterDuplicate = (array: any[]) => { + return array.filter(function (item: any, pos: number) { + return array.indexOf(item) == pos; + }); +}; + const makeGetSoftwareById = (db: Kysely) => async (softwareId: number): Promise => @@ -551,6 +559,9 @@ const makeGetSoftwareById = testUrl: testUrls[0]?.url, parentWikidataSoftware: parentExternalData, programmingLanguages: softwareExternalData?.programmingLanguages ?? [], - applicationCategories: software.categories.concat(softwareExternalData?.applicationCategories ?? []) + applicationCategories: filterDuplicate( + software.categories.concat(softwareExternalData?.applicationCategories ?? []) + ), + categories: undefined // merged in applicationCategories, set to undefined to remove it }); }); diff --git a/api/src/core/adapters/dbApi/kysely/pgDbApi.integration.test.ts b/api/src/core/adapters/dbApi/kysely/pgDbApi.integration.test.ts index 4a38a537..d8583e56 100644 --- a/api/src/core/adapters/dbApi/kysely/pgDbApi.integration.test.ts +++ b/api/src/core/adapters/dbApi/kysely/pgDbApi.integration.test.ts @@ -166,7 +166,6 @@ describe("pgDbApi", () => { authorName: dev.name, authorUrl: `https://www.wikidata.org/wiki/${dev.id}` })), - categories: [], codeRepositoryUrl: softwareExternalData.sourceUrl, comptoirDuLibreId: 50, comptoirDuLibreServiceProviderCount: 0, diff --git a/api/src/core/usecases/readWriteSillData/types.ts b/api/src/core/usecases/readWriteSillData/types.ts index 3003b720..181a4a50 100644 --- a/api/src/core/usecases/readWriteSillData/types.ts +++ b/api/src/core/usecases/readWriteSillData/types.ts @@ -34,7 +34,7 @@ export type Software = { lastRecommendedVersion?: string; } | undefined; - categories: string[]; + applicationCategories: string[]; prerogatives: Prerogatives; userAndReferentCountByOrganization: Record; authors: { @@ -62,7 +62,6 @@ export type Software = { similarSoftwares: Software.SimilarSoftware[]; keywords: string[]; programmingLanguages: string[]; - applicationCategories: string[]; }; export namespace Software {