From b0f5f1f52c42561680db90c4e0c5954ee5bfac1e Mon Sep 17 00:00:00 2001 From: Ryan Goetz Date: Tue, 3 Sep 2024 09:50:25 -1000 Subject: [PATCH] Update e2e unit test * Updated how to upload the dictionaries. --- sequencing-server/jest.config.js | 2 +- .../batchLoaders/expansionBatchLoader.spec.ts | 6 +-- .../expansionSetBatchLoader.spec.ts | 6 +-- .../test/command-expansion.spec.ts | 6 +-- sequencing-server/test/command-types.spec.ts | 6 +-- sequencing-server/test/db-state.spec.ts | 6 +-- sequencing-server/test/dictionary.spec.ts | 30 +++++------ .../test/sequence-generation.spec.ts | 6 +-- .../test/testUtils/Dictionary.ts | 53 ++++++++++++------- 9 files changed, 69 insertions(+), 52 deletions(-) diff --git a/sequencing-server/jest.config.js b/sequencing-server/jest.config.js index ccd4beccb1..54f2b54a28 100644 --- a/sequencing-server/jest.config.js +++ b/sequencing-server/jest.config.js @@ -13,7 +13,7 @@ export default { testRunner: 'jest-circus/runner', // testRegex: "(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", testRegex: '((\\.|/)(test|spec))\\.(jsx?|tsx?)$', - testPathIgnorePatterns: ['/node_modules/', '/build/'], + testPathIgnorePatterns: ['/node_modules/', '/build/', '/plugins/'], coverageReporters: ['html'], setupFiles: ['dotenv/config', './src/polyfills.ts'], globalSetup: './jestGlobalSetup.js', diff --git a/sequencing-server/test/batchLoaders/expansionBatchLoader.spec.ts b/sequencing-server/test/batchLoaders/expansionBatchLoader.spec.ts index b9b53e8562..7a2b12621d 100644 --- a/sequencing-server/test/batchLoaders/expansionBatchLoader.spec.ts +++ b/sequencing-server/test/batchLoaders/expansionBatchLoader.spec.ts @@ -15,9 +15,9 @@ let parcelId: number; beforeAll(async () => { graphqlClient = await getGraphQLClient(); - commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id; - channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id; - parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id; + commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id; + channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id; + parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id; parcelId = ( await insertParcel( graphqlClient, diff --git a/sequencing-server/test/batchLoaders/expansionSetBatchLoader.spec.ts b/sequencing-server/test/batchLoaders/expansionSetBatchLoader.spec.ts index fbb6673109..cc23a0e096 100644 --- a/sequencing-server/test/batchLoaders/expansionSetBatchLoader.spec.ts +++ b/sequencing-server/test/batchLoaders/expansionSetBatchLoader.spec.ts @@ -18,9 +18,9 @@ let parcelId: number; beforeAll(async () => { graphqlClient = await getGraphQLClient(); - commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id; - channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id; - paramaterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id; + commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id; + channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id; + paramaterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id; parcelId = ( await insertParcel( graphqlClient, diff --git a/sequencing-server/test/command-expansion.spec.ts b/sequencing-server/test/command-expansion.spec.ts index 7d6f810c80..92604b1004 100644 --- a/sequencing-server/test/command-expansion.spec.ts +++ b/sequencing-server/test/command-expansion.spec.ts @@ -34,9 +34,9 @@ let parcelId: number; beforeAll(async () => { graphqlClient = await getGraphQLClient(); - commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id; - channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id; - parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id; + commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id; + channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id; + parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id; parcelId = ( await insertParcel( graphqlClient, diff --git a/sequencing-server/test/command-types.spec.ts b/sequencing-server/test/command-types.spec.ts index ef9e4d1805..139d5257c4 100644 --- a/sequencing-server/test/command-types.spec.ts +++ b/sequencing-server/test/command-types.spec.ts @@ -11,9 +11,9 @@ let parameterDictionaryId: number; beforeAll(async () => { graphqlClient = await getGraphQLClient(); - commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id; - channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id; - parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id; + commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id; + channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id; + parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id; }); afterAll(async () => { diff --git a/sequencing-server/test/db-state.spec.ts b/sequencing-server/test/db-state.spec.ts index f96f024821..eb5fefae1d 100644 --- a/sequencing-server/test/db-state.spec.ts +++ b/sequencing-server/test/db-state.spec.ts @@ -33,9 +33,9 @@ beforeAll(async () => { }); beforeEach(async () => { - commandDictonaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id; - channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id; - parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id; + commandDictonaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id; + channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id; + parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id; parcelId = ( await insertParcel(graphqlClient, commandDictonaryId, channelDictionaryId, parameterDictionaryId, 'db-parcel-test') ).parcelId; diff --git a/sequencing-server/test/dictionary.spec.ts b/sequencing-server/test/dictionary.spec.ts index 02c93dcd7a..822e8713c9 100644 --- a/sequencing-server/test/dictionary.spec.ts +++ b/sequencing-server/test/dictionary.spec.ts @@ -19,43 +19,43 @@ beforeAll(async () => { describe('upload dictionaries', () => { it('should upload a command dictionary and all of the fields should be populated correctly', async () => { // During the test we use a uuid for the mission so there's no conflicting command dictionaries. - const { id, dictionary_path, mission, parsed_json } = await insertDictionary(graphqlClient, DictionaryType.COMMAND); + const { command } = await insertDictionary(graphqlClient, DictionaryType.COMMAND); - expect(dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${mission}/command_lib.${mission}.ts`); + expect(command.dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${command.mission}/command_lib.${command.mission}.ts`); - expect(parsed_json).toStrictEqual( - ampcs.parse(commandDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, mission)), + expect(command.parsed_json).toStrictEqual( + ampcs.parse(commandDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, command.mission)), ); - await removeDictionary(graphqlClient, id, DictionaryType.COMMAND); + await removeDictionary(graphqlClient, command.id, DictionaryType.COMMAND); }, 30000); it('should upload a channel dictionary and all of the fields should be populated correctly', async () => { // During the test we use a uuid for the mission so there's no conflicting command dictionaries. - const { id, dictionary_path, mission, parsed_json } = await insertDictionary(graphqlClient, DictionaryType.CHANNEL); + const { channel } = await insertDictionary(graphqlClient, DictionaryType.CHANNEL); - expect(dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${mission}/channel_lib.${mission}.ts`); + expect(channel.dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${channel.mission}/channel_lib.${channel.mission}.ts`); - expect(parsed_json).toEqual( - ampcs.parseChannelDictionary(channelDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, mission)), + expect(channel.parsed_json).toEqual( + ampcs.parseChannelDictionary(channelDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, channel.mission)), ); - await removeDictionary(graphqlClient, id, DictionaryType.CHANNEL); + await removeDictionary(graphqlClient, channel.id, DictionaryType.CHANNEL); }, 30000); it('should upload a parameter dictionary and all of the fields should be populated correctly', async () => { // During the test we use a uuid for the mission so there's no conflicting command dictionaries. - const { id, dictionary_path, mission, parsed_json } = await insertDictionary( + const { parameter } = await insertDictionary( graphqlClient, DictionaryType.PARAMETER, ); - expect(dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${mission}/parameter_lib.${mission}.ts`); + expect(parameter.dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${parameter.mission}/parameter_lib.${parameter.mission}.ts`); - expect(parsed_json).toEqual( - ampcs.parseParameterDictionary(parameterDictionaryString.replace(/(Banana Nation|1.0.0.1)/g, mission)), + expect(parameter.parsed_json).toEqual( + ampcs.parseParameterDictionary(parameterDictionaryString.replace(/(Banana Nation|1.0.0.1)/g, parameter.mission)), ); - await removeDictionary(graphqlClient, id, DictionaryType.PARAMETER); + await removeDictionary(graphqlClient, parameter.id, DictionaryType.PARAMETER); }, 30000); }); diff --git a/sequencing-server/test/sequence-generation.spec.ts b/sequencing-server/test/sequence-generation.spec.ts index 683819c300..20a0838d65 100644 --- a/sequencing-server/test/sequence-generation.spec.ts +++ b/sequencing-server/test/sequence-generation.spec.ts @@ -38,9 +38,9 @@ let parcelId: number; beforeAll(async () => { graphqlClient = await getGraphQLClient(); - commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id; - channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id; - parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id; + commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id; + channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id; + parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id; parcelId = ( await insertParcel( graphqlClient, diff --git a/sequencing-server/test/testUtils/Dictionary.ts b/sequencing-server/test/testUtils/Dictionary.ts index 08d91f91d2..721ef5dc18 100644 --- a/sequencing-server/test/testUtils/Dictionary.ts +++ b/sequencing-server/test/testUtils/Dictionary.ts @@ -22,11 +22,21 @@ export async function insertDictionary( graphqlClient: GraphQLClient, type: DictionaryType, ): Promise<{ - id: number; - dictionary_path: string; - mission: string; - version: string; - parsed_json: CommandDictionary | ChannelDictionary | ParameterDictionary; + command: {id: number; + dictionary_path: string; + mission: string; + version: string; + parsed_json: CommandDictionary} + parameter: {id: number; + dictionary_path: string; + mission: string; + version: string; + parsed_json: ParameterDictionary} + channel: {id: number; + dictionary_path: string; + mission: string; + version: string; + parsed_json: ChannelDictionary} }> { let dictonaryString = commandDictionaryString; switch (type) { @@ -39,28 +49,35 @@ export async function insertDictionary( } const res = await graphqlClient.request<{ uploadDictionary: { - id: number; - dictionary_path: string; - mission: string; - version: string; - parsed_json: CommandDictionary | ChannelDictionary | ParameterDictionary; + command: {id: number; + dictionary_path: string; + mission: string; + version: string; + parsed_json: CommandDictionary} + parameter: {id: number; + dictionary_path: string; + mission: string; + version: string; + parsed_json: ParameterDictionary} + channel: {id: number; + dictionary_path: string; + mission: string; + version: string; + parsed_json: ChannelDictionary} }; }>( gql` - mutation PutDictionary($dictionary: String!, $type: String!) { - uploadDictionary(dictionary: $dictionary, type: $type) { - id - dictionary_path - mission - version - parsed_json + mutation PutDictionary($dictionary: String!) { + uploadDictionary(dictionary: $dictionary) { + command + parameter + channel } } `, { // Generate a UUID for the command dictionary name and version to avoid conflicts when testing. dictionary: dictonaryString.replace(/(Banana Nation|1.0.0.0|1.0.0.1)/g, randomUUID()), - type, }, );