From d761727b5256f78a5630e28adbb2ce845d9ded8c Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 09:54:03 +0530 Subject: [PATCH 01/10] fix: stringifying session ID for airship --- .../airship/data/airshipTrackConfig.json | 5 +- .../destinations/airship/processor/data.ts | 89 ++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/v0/destinations/airship/data/airshipTrackConfig.json b/src/v0/destinations/airship/data/airshipTrackConfig.json index 1f280f756b..4b09fdb943 100644 --- a/src/v0/destinations/airship/data/airshipTrackConfig.json +++ b/src/v0/destinations/airship/data/airshipTrackConfig.json @@ -22,7 +22,10 @@ { "destKey": "session_id", "sourceKeys": ["properties.sessionId", "context.sessionId"], - "required": false + "required": false, + "metadata": { + "type": "toString" + } }, { "destKey": "transaction", diff --git a/test/integrations/destinations/airship/processor/data.ts b/test/integrations/destinations/airship/processor/data.ts index a72495d23d..36a012e73e 100644 --- a/test/integrations/destinations/airship/processor/data.ts +++ b/test/integrations/destinations/airship/processor/data.ts @@ -2296,7 +2296,7 @@ export const data = [ }, { name: 'airship', - description: 'Test 22 : session id gets converted to v5 uuid format', + description: 'Test 22 : session id from Web SDK gets converted to v5 uuid format', feature: 'processor', module: 'destination', version: 'v0', @@ -2381,6 +2381,93 @@ export const data = [ }, }, }, + { + name: 'airship', + description: 'Test 22 : session id from mobile SDK gets converted to v5 uuid format', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + channel: 'web', + context: { + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.0.0', + }, + traits: { email: 'testone@gmail.com', firstName: 'test', lastName: 'one' }, + library: { name: 'RudderLabs JavaScript SDK', version: '1.0.0' }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', + locale: 'en-US', + ip: '0.0.0.0', + os: { name: '', version: '' }, + screen: { density: 2 }, + sessionId: 1731403898, + }, + type: 'track', + messageId: '84e26acc-56a5-4835-8233-591137fca468', + anonymousId: '123456', + event: 'Product Clicked', + userId: 'testuserId1', + properties: {}, + integrations: { All: true }, + }, + destination: { + Config: { + apiKey: 'dummyApiKey', + appKey: 'ffdf', + dataCenter: false, + }, + }, + }, + ], + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://go.urbanairship.com/api/custom-events', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/vnd.urbanairship+json; version=3', + 'X-UA-Appkey': 'ffdf', + Authorization: 'Bearer dummyApiKey', + }, + params: {}, + body: { + JSON: { + user: { named_user_id: 'testuserId1' }, + body: { + name: 'product_clicked', + session_id: 'd5627eac-795d-5005-9bb4-2c7c0af6cab0', + }, + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + }, + ], + }, + }, + }, ].map((tc) => ({ ...tc, mockFns: (_) => { From 3bf1362e4873103b63cc5b53fdfdfe06476bf4fe Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 10:02:34 +0530 Subject: [PATCH 02/10] fix: test case numbering fix --- test/integrations/destinations/airship/processor/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integrations/destinations/airship/processor/data.ts b/test/integrations/destinations/airship/processor/data.ts index 36a012e73e..e37227d9d2 100644 --- a/test/integrations/destinations/airship/processor/data.ts +++ b/test/integrations/destinations/airship/processor/data.ts @@ -2383,7 +2383,7 @@ export const data = [ }, { name: 'airship', - description: 'Test 22 : session id from mobile SDK gets converted to v5 uuid format', + description: 'Test 23 : session id from mobile SDK gets converted to v5 uuid format', feature: 'processor', module: 'destination', version: 'v0', From 6742c924a39a2e1e222edae02d7f9bbee2aed157 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 12:31:16 +0530 Subject: [PATCH 03/10] fix: adding more test cases --- .../destinations/airship/processor/data.ts | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/test/integrations/destinations/airship/processor/data.ts b/test/integrations/destinations/airship/processor/data.ts index e37227d9d2..3c6d827ce6 100644 --- a/test/integrations/destinations/airship/processor/data.ts +++ b/test/integrations/destinations/airship/processor/data.ts @@ -2468,6 +2468,180 @@ export const data = [ }, }, }, + { + name: 'airship', + description: 'Test 24 : session id null gets ignored', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + channel: 'web', + context: { + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.0.0', + }, + traits: { email: 'testone@gmail.com', firstName: 'test', lastName: 'one' }, + library: { name: 'RudderLabs JavaScript SDK', version: '1.0.0' }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', + locale: 'en-US', + ip: '0.0.0.0', + os: { name: '', version: '' }, + screen: { density: 2 }, + }, + type: 'track', + messageId: '84e26acc-56a5-4835-8233-591137fca468', + anonymousId: '123456', + event: 'Product Clicked', + userId: 'testuserId1', + properties: { + sessionId: null, + }, + integrations: { All: true }, + }, + destination: { + Config: { + apiKey: 'dummyApiKey', + appKey: 'ffdf', + dataCenter: false, + }, + }, + }, + ], + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://go.urbanairship.com/api/custom-events', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/vnd.urbanairship+json; version=3', + 'X-UA-Appkey': 'ffdf', + Authorization: 'Bearer dummyApiKey', + }, + params: {}, + body: { + JSON: { + user: { named_user_id: 'testuserId1' }, + body: { + name: 'product_clicked', + }, + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + }, + ], + }, + }, + }, + { + name: 'airship', + description: 'Test 24 : session id undefined gets ignored', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + channel: 'web', + context: { + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.0.0', + }, + traits: { email: 'testone@gmail.com', firstName: 'test', lastName: 'one' }, + library: { name: 'RudderLabs JavaScript SDK', version: '1.0.0' }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36', + locale: 'en-US', + ip: '0.0.0.0', + os: { name: '', version: '' }, + screen: { density: 2 }, + }, + type: 'track', + messageId: '84e26acc-56a5-4835-8233-591137fca468', + anonymousId: '123456', + event: 'Product Clicked', + userId: 'testuserId1', + properties: { + sessionId: undefined, + }, + integrations: { All: true }, + }, + destination: { + Config: { + apiKey: 'dummyApiKey', + appKey: 'ffdf', + dataCenter: false, + }, + }, + }, + ], + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://go.urbanairship.com/api/custom-events', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/vnd.urbanairship+json; version=3', + 'X-UA-Appkey': 'ffdf', + Authorization: 'Bearer dummyApiKey', + }, + params: {}, + body: { + JSON: { + user: { named_user_id: 'testuserId1' }, + body: { + name: 'product_clicked', + }, + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + }, + ], + }, + }, + }, ].map((tc) => ({ ...tc, mockFns: (_) => { From 4833183989d261ded839e1db499f6e05a6bc41e5 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 13:36:22 +0530 Subject: [PATCH 04/10] fix: review comment addressed --- src/v0/destinations/airship/transform.js | 4 +++- src/v0/destinations/airship/utils.js | 12 ------------ src/v0/util/index.js | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) delete mode 100644 src/v0/destinations/airship/utils.js diff --git a/src/v0/destinations/airship/transform.js b/src/v0/destinations/airship/transform.js index dc8543fbc5..29b529b1e7 100644 --- a/src/v0/destinations/airship/transform.js +++ b/src/v0/destinations/airship/transform.js @@ -22,9 +22,9 @@ const { extractCustomFields, isEmptyObject, simpleProcessRouterDest, + transformSessionId, } = require('../../util'); const { JSON_MIME_TYPE } = require('../../util/constant'); -const { transformSessionId } = require('./utils'); const DEFAULT_ACCEPT_HEADER = 'application/vnd.urbanairship+json; version=3'; @@ -129,6 +129,8 @@ const trackResponseBuilder = async (message, { Config }) => { name = name.toLowerCase(); const payload = constructPayload(message, trackMapping); + + // ref : https://docs.airship.com/api/ua/#operation-api-custom-events-post if (isDefinedAndNotNullAndNotEmpty(payload.session_id)) { payload.session_id = transformSessionId(payload.session_id); } diff --git a/src/v0/destinations/airship/utils.js b/src/v0/destinations/airship/utils.js deleted file mode 100644 index 0ef637245f..0000000000 --- a/src/v0/destinations/airship/utils.js +++ /dev/null @@ -1,12 +0,0 @@ -const { v5 } = require('uuid'); - -// ref : https://docs.airship.com/api/ua/#operation-api-custom-events-post -const transformSessionId = (rawSessionId) => { - const NAMESPACE = v5.DNS; - const uuidV5 = v5(rawSessionId, NAMESPACE); - return uuidV5; -}; - -module.exports = { - transformSessionId, -}; diff --git a/src/v0/util/index.js b/src/v0/util/index.js index 1676498fdb..8bcd811774 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -16,6 +16,7 @@ const uaParser = require('ua-parser-js'); const moment = require('moment-timezone'); const sha256 = require('sha256'); const crypto = require('crypto'); +const { v5 } = require('uuid'); const { InstrumentationError, BaseError, @@ -2330,6 +2331,28 @@ const isEventSentByVDMV1Flow = (event) => event?.message?.context?.mappedToDesti const isEventSentByVDMV2Flow = (event) => event?.connection?.config?.destination?.schemaVersion === VDM_V2_SCHEMA_VERSION; + +const validateSessionId = (rawSessionId) => { + const sessionId = String(rawSessionId).trim(); // Attempt conversion to string and trim whitespace + if (!sessionId) { + throw new InstrumentationError( + '[TransformSessionId] Invalid session ID: must be a non-empty string after conversion to string.', + ); + } + return sessionId; // Return the validated and converted session ID +}; + +const transformSessionId = (rawSessionId) => { + try { + const sessionId = validateSessionId(rawSessionId); + + const NAMESPACE = v5.DNS; + const uuidV5 = v5(sessionId, NAMESPACE); + return uuidV5; + } catch (error) { + throw new InstrumentationError(`Failed to transform session ID: ${error.message}`); + } +}; // ======================================================================== // EXPORTS // ======================================================================== @@ -2456,4 +2479,5 @@ module.exports = { getRelativePathFromURL, removeEmptyKey, isAxiosError, + transformSessionId, }; From 84d478b0370a17a76b7479e295776744ff3c3486 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 13:37:55 +0530 Subject: [PATCH 05/10] fix: edit error message --- src/v0/util/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v0/util/index.js b/src/v0/util/index.js index 8bcd811774..a032c763f1 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -2336,7 +2336,7 @@ const validateSessionId = (rawSessionId) => { const sessionId = String(rawSessionId).trim(); // Attempt conversion to string and trim whitespace if (!sessionId) { throw new InstrumentationError( - '[TransformSessionId] Invalid session ID: must be a non-empty string after conversion to string.', + 'Invalid session ID: must be a non-empty string after conversion to string.', ); } return sessionId; // Return the validated and converted session ID From 82ffd9b995b7ca456afc2a3e83199dc9d6dd22ad Mon Sep 17 00:00:00 2001 From: krishnachaitanya Date: Thu, 21 Nov 2024 13:53:59 +0530 Subject: [PATCH 06/10] chore: refactored code --- src/v0/destinations/airship/transform.js | 12 +++++++++++- src/v0/util/index.js | 24 ++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/v0/destinations/airship/transform.js b/src/v0/destinations/airship/transform.js index 29b529b1e7..f4459c08b6 100644 --- a/src/v0/destinations/airship/transform.js +++ b/src/v0/destinations/airship/transform.js @@ -22,12 +22,22 @@ const { extractCustomFields, isEmptyObject, simpleProcessRouterDest, - transformSessionId, + convertToUuid, } = require('../../util'); const { JSON_MIME_TYPE } = require('../../util/constant'); const DEFAULT_ACCEPT_HEADER = 'application/vnd.urbanairship+json; version=3'; +const transformSessionId = (rawSessionId) => { + const sessionId = String(rawSessionId).trim(); // Attempt conversion to string and trim whitespace + if (!sessionId) { + throw new InstrumentationError( + 'Invalid session ID: must be a non-empty string after conversion to string.', + ); + } + return convertToUuid(sessionId); // Return the validated and converted session ID +}; + const identifyResponseBuilder = (message, { Config }) => { const tagPayload = constructPayload(message, identifyMapping); const { apiKey, dataCenter } = Config; diff --git a/src/v0/util/index.js b/src/v0/util/index.js index a032c763f1..314e6c1818 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -2332,25 +2332,13 @@ const isEventSentByVDMV1Flow = (event) => event?.message?.context?.mappedToDesti const isEventSentByVDMV2Flow = (event) => event?.connection?.config?.destination?.schemaVersion === VDM_V2_SCHEMA_VERSION; -const validateSessionId = (rawSessionId) => { - const sessionId = String(rawSessionId).trim(); // Attempt conversion to string and trim whitespace - if (!sessionId) { - throw new InstrumentationError( - 'Invalid session ID: must be a non-empty string after conversion to string.', - ); - } - return sessionId; // Return the validated and converted session ID -}; - -const transformSessionId = (rawSessionId) => { +const convertToUuid = (input) => { + const NAMESPACE = v5.DNS; try { - const sessionId = validateSessionId(rawSessionId); - - const NAMESPACE = v5.DNS; - const uuidV5 = v5(sessionId, NAMESPACE); - return uuidV5; + return v5(input, NAMESPACE); } catch (error) { - throw new InstrumentationError(`Failed to transform session ID: ${error.message}`); + const errorMessage = `Failed to transform input to uuid: ${error.message}`; + throw new InstrumentationError(errorMessage); } }; // ======================================================================== @@ -2479,5 +2467,5 @@ module.exports = { getRelativePathFromURL, removeEmptyKey, isAxiosError, - transformSessionId, + convertToUuid, }; From 5360d144a81cc6b915920949b1a5db8247c09acc Mon Sep 17 00:00:00 2001 From: krishnachaitanya Date: Thu, 21 Nov 2024 14:13:43 +0530 Subject: [PATCH 07/10] chore: handled stringifcation in convertToUuid --- src/v0/destinations/airship/transform.js | 10 ++++------ src/v0/util/index.js | 10 +++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/v0/destinations/airship/transform.js b/src/v0/destinations/airship/transform.js index f4459c08b6..fcf18daa7e 100644 --- a/src/v0/destinations/airship/transform.js +++ b/src/v0/destinations/airship/transform.js @@ -29,13 +29,11 @@ const { JSON_MIME_TYPE } = require('../../util/constant'); const DEFAULT_ACCEPT_HEADER = 'application/vnd.urbanairship+json; version=3'; const transformSessionId = (rawSessionId) => { - const sessionId = String(rawSessionId).trim(); // Attempt conversion to string and trim whitespace - if (!sessionId) { - throw new InstrumentationError( - 'Invalid session ID: must be a non-empty string after conversion to string.', - ); + try { + return convertToUuid(rawSessionId); + } catch (error) { + throw new InstrumentationError(`Failed to transform session ID: ${error.message}`); } - return convertToUuid(sessionId); // Return the validated and converted session ID }; const identifyResponseBuilder = (message, { Config }) => { diff --git a/src/v0/util/index.js b/src/v0/util/index.js index 314e6c1818..eb00b67836 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -2335,7 +2335,15 @@ const isEventSentByVDMV2Flow = (event) => const convertToUuid = (input) => { const NAMESPACE = v5.DNS; try { - return v5(input, NAMESPACE); + // Stringify and trim the input + const trimmedInput = String(input).trim(); + + // Check for empty input after trimming + if (!trimmedInput) { + throw new InstrumentationError('Input is empty or invalid.'); + } + // Generate and return UUID + return v5(trimmedInput, NAMESPACE); } catch (error) { const errorMessage = `Failed to transform input to uuid: ${error.message}`; throw new InstrumentationError(errorMessage); From f684c10fb110011ebb417a49e862705fe6a452f9 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 14:40:30 +0530 Subject: [PATCH 08/10] fix: adding test cases --- src/v0/util/index.test.js | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/v0/util/index.test.js b/src/v0/util/index.test.js index 0b05b6f2d6..810e0247bd 100644 --- a/src/v0/util/index.test.js +++ b/src/v0/util/index.test.js @@ -2,6 +2,7 @@ const { InstrumentationError } = require('@rudderstack/integrations-lib'); const utilities = require('.'); const { getFuncTestData } = require('../../../test/testHelper'); const { FilteredEventsError } = require('./errorTypes'); +const { v5 } = require('uuid'); const { hasCircularReference, flattenJson, @@ -11,6 +12,7 @@ const { groupRouterTransformEvents, isAxiosError, removeHyphens, + convertToUuid, } = require('./index'); const exp = require('constants'); @@ -985,3 +987,65 @@ describe('removeHyphens', () => { }); }); }); + +describe('convertToUuid', () => { + const NAMESPACE = v5.DNS; + + test('should generate UUID for valid string input', () => { + const input = 'testInput'; + const expectedUuid = v5(input, NAMESPACE); + const result = convertToUuid(input); + expect(result).toBe(expectedUuid); + }); + + test('should generate UUID for valid numeric input', () => { + const input = 123456; + const expectedUuid = v5(String(input), NAMESPACE); + const result = convertToUuid(input); + expect(result).toBe(expectedUuid); + }); + + test('should trim spaces and generate UUID', () => { + const input = ' testInput '; + const expectedUuid = v5('testInput', NAMESPACE); + const result = convertToUuid(input); + expect(result).toBe(expectedUuid); + }); + + test('should throw an error for empty input', () => { + const input = ''; + expect(() => convertToUuid(input)).toThrow(InstrumentationError); + expect(() => convertToUuid(input)).toThrow('Input is empty or invalid.'); + }); + + test('does not throw an error for null input', () => { + const input = null; + const result = convertToUuid(input); + expect(result).toBe('14fe171b-730d-5a16-8d75-fccfea2e4267'); + }); + + test('does not throw an error for undefined input', () => { + const input = undefined; + const result = convertToUuid(input); + expect(result).toBe('fb6fdadc-7f92-59fe-9a2c-87b5b3b62522'); + }); + + test('should throw an error for input that is whitespace only', () => { + const input = ' '; + expect(() => convertToUuid(input)).toThrow(InstrumentationError); + expect(() => convertToUuid(input)).toThrow('Input is empty or invalid.'); + }); + + test('should handle long string input gracefully', () => { + const input = 'a'.repeat(1000); + const expectedUuid = v5(input, NAMESPACE); + const result = convertToUuid(input); + expect(result).toBe(expectedUuid); + }); + + test('should throw an error and log the correct message for invalid input', () => { + const input = {}; + const result = convertToUuid(input); + expect(result).toBe('672ca00c-37f4-5d71-b8c3-6ae0848080ec'); + }); +}); From 685127213eb58478d8ba560a587b44b0d38de41b Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 14:42:22 +0530 Subject: [PATCH 09/10] fix: small edit --- src/v0/util/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v0/util/index.test.js b/src/v0/util/index.test.js index 810e0247bd..d8e13fed43 100644 --- a/src/v0/util/index.test.js +++ b/src/v0/util/index.test.js @@ -1043,7 +1043,7 @@ describe('convertToUuid', () => { expect(result).toBe(expectedUuid); }); - test('should throw an error and log the correct message for invalid input', () => { + test('any invalid input if stringified does not throw error', () => { const input = {}; const result = convertToUuid(input); expect(result).toBe('672ca00c-37f4-5d71-b8c3-6ae0848080ec'); From 795a5d34ad61c68f709f320eead8a394b825271a Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Thu, 21 Nov 2024 15:20:13 +0530 Subject: [PATCH 10/10] fix: code review addressed --- src/v0/util/index.js | 5 +++++ src/v0/util/index.test.js | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/v0/util/index.js b/src/v0/util/index.js index eb00b67836..ad08be448e 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -2334,6 +2334,11 @@ const isEventSentByVDMV2Flow = (event) => const convertToUuid = (input) => { const NAMESPACE = v5.DNS; + + if (!isDefinedAndNotNull(input)) { + throw new InstrumentationError('Input is undefined or null.'); + } + try { // Stringify and trim the input const trimmedInput = String(input).trim(); diff --git a/src/v0/util/index.test.js b/src/v0/util/index.test.js index d8e13fed43..cfdfefddee 100644 --- a/src/v0/util/index.test.js +++ b/src/v0/util/index.test.js @@ -993,21 +993,21 @@ describe('convertToUuid', () => { test('should generate UUID for valid string input', () => { const input = 'testInput'; - const expectedUuid = v5(input, NAMESPACE); + const expectedUuid = '7ba1e88f-acf9-5528-9c1c-0c897ed80e1e'; const result = convertToUuid(input); expect(result).toBe(expectedUuid); }); test('should generate UUID for valid numeric input', () => { const input = 123456; - const expectedUuid = v5(String(input), NAMESPACE); + const expectedUuid = 'a52b2702-9bcf-5701-852a-2f4edc640fe1'; const result = convertToUuid(input); expect(result).toBe(expectedUuid); }); test('should trim spaces and generate UUID', () => { const input = ' testInput '; - const expectedUuid = v5('testInput', NAMESPACE); + const expectedUuid = '7ba1e88f-acf9-5528-9c1c-0c897ed80e1e'; const result = convertToUuid(input); expect(result).toBe(expectedUuid); }); @@ -1018,16 +1018,16 @@ describe('convertToUuid', () => { expect(() => convertToUuid(input)).toThrow('Input is empty or invalid.'); }); - test('does not throw an error for null input', () => { + test('to throw an error for null input', () => { const input = null; - const result = convertToUuid(input); - expect(result).toBe('14fe171b-730d-5a16-8d75-fccfea2e4267'); + expect(() => convertToUuid(input)).toThrow(InstrumentationError); + expect(() => convertToUuid(input)).toThrow('Input is undefined or null'); }); - test('does not throw an error for undefined input', () => { + test('to throw an error for undefined input', () => { const input = undefined; - const result = convertToUuid(input); - expect(result).toBe('fb6fdadc-7f92-59fe-9a2c-87b5b3b62522'); + expect(() => convertToUuid(input)).toThrow(InstrumentationError); + expect(() => convertToUuid(input)).toThrow('Input is undefined or null'); }); test('should throw an error for input that is whitespace only', () => {