From bf4349de56f03912d196771347c3ae2b54a0ef1d Mon Sep 17 00:00:00 2001 From: Seth Orell Date: Wed, 1 Nov 2023 08:37:31 -0500 Subject: [PATCH] Add test for various prefix characters --- package-lock.json | 14 +++---- package.json | 2 +- test/create.int.test.ts | 93 +++++++++++++++++++++++++++++------------ 3 files changed, 74 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index 384e35f7..d3132204 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@swc/core": "^1.3.91", "@swc/jest": "^0.2.24", "@tsconfig/node18": "^18.2.0", - "@types/async-retry": "^1.4.6", + "@types/async-retry": "^1.4.7", "@types/http-errors": "^2.0.2", "@types/jest": "^29.5.5", "@typescript-eslint/eslint-plugin": "^6.7.4", @@ -3061,9 +3061,9 @@ "dev": true }, "node_modules/@types/async-retry": { - "version": "1.4.6", - "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.6.tgz", - "integrity": "sha512-or8JPgYUtyPpO0ddHImwUWmSjVE/UalxgMm2d0r3698QhjzlM7eke0PT60bOxs1NG7HxU232RQ1vy1iQKGGRTw==", + "version": "1.4.7", + "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.7.tgz", + "integrity": "sha512-4NH5wuf9x7LZWD23/knI6RBywD1qCmLm7wNaqq0riy7hdDrCGGfkPOUvx0Cb78lVrFrEnCvocoL8+UcvSQlBDw==", "dev": true, "dependencies": { "@types/retry": "*" @@ -11479,9 +11479,9 @@ "dev": true }, "@types/async-retry": { - "version": "1.4.6", - "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.6.tgz", - "integrity": "sha512-or8JPgYUtyPpO0ddHImwUWmSjVE/UalxgMm2d0r3698QhjzlM7eke0PT60bOxs1NG7HxU232RQ1vy1iQKGGRTw==", + "version": "1.4.7", + "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.7.tgz", + "integrity": "sha512-4NH5wuf9x7LZWD23/knI6RBywD1qCmLm7wNaqq0riy7hdDrCGGfkPOUvx0Cb78lVrFrEnCvocoL8+UcvSQlBDw==", "dev": true, "requires": { "@types/retry": "*" diff --git a/package.json b/package.json index ffba64f9..1c28c6ac 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@swc/core": "^1.3.91", "@swc/jest": "^0.2.24", "@tsconfig/node18": "^18.2.0", - "@types/async-retry": "^1.4.6", + "@types/async-retry": "^1.4.7", "@types/http-errors": "^2.0.2", "@types/jest": "^29.5.5", "@typescript-eslint/eslint-plugin": "^6.7.4", diff --git a/test/create.int.test.ts b/test/create.int.test.ts index 27df572b..8c855ceb 100644 --- a/test/create.int.test.ts +++ b/test/create.int.test.ts @@ -21,7 +21,7 @@ describe('When creating item', () => { it('should save item to db', async () => { // ARRANGE - const item = await createTestKeyValueItem(); + const item = createTestKeyValueItem(); const repo = new KeyValueRepository({ tableName: TableName, keyName: KeyName, documentClient }); // ACT @@ -29,16 +29,19 @@ describe('When creating item', () => { testKeys.push(key); // ASSERT - await retry(async () => { - const itemFromDB = await fetchHashKeyItem(key); - expect(itemFromDB).not.toBeUndefined(); - expect(itemFromDB?.field1).toEqual(item.field1); - }, { retries: 3 }); + await retry( + async () => { + const itemFromDB = await fetchHashKeyItem(key); + expect(itemFromDB).not.toBeUndefined(); + expect(itemFromDB?.field1).toEqual(item.field1); + }, + { retries: 3 }, + ); }); it('should replace any id on provided item', async () => { // ARRANGE - const item = await createTestKeyValueItem(); + const item = createTestKeyValueItem(); const repo = new KeyValueRepository({ tableName: TableName, keyName: KeyName, documentClient }); // ACT @@ -46,16 +49,19 @@ describe('When creating item', () => { testKeys.push(key); // ASSERT - await retry(async () => { - expect(key).not.toEqual(item.key); - const itemFromDB = await fetchHashKeyItem(key); - expect(itemFromDB?.key).not.toEqual(item.key); - }, { retries: 3 }); + await retry( + async () => { + expect(key).not.toEqual(item.key); + const itemFromDB = await fetchHashKeyItem(key); + expect(itemFromDB?.key).not.toEqual(item.key); + }, + { retries: 3 }, + ); }); it('should set createdAt and updateAt', async () => { // ARRANGE - const item = await createTestKeyValueItem(); + const item = createTestKeyValueItem(); const repo = new KeyValueRepository({ tableName: TableName, keyName: KeyName, documentClient }); // ACT @@ -63,19 +69,22 @@ describe('When creating item', () => { testKeys.push(result.key); // ASSERT - await retry(async () => { - expect(result.createdAt).not.toBeUndefined(); - expect(result.createdAt).toEqual(result.updatedAt); - const itemFromDB = await fetchHashKeyItem(result.key); - expect(itemFromDB?.createdAt).not.toBeUndefined(); - expect(itemFromDB?.createdAt).toEqual(itemFromDB?.updatedAt); - }, { retries: 3 }); + await retry( + async () => { + expect(result.createdAt).not.toBeUndefined(); + expect(result.createdAt).toEqual(result.updatedAt); + const itemFromDB = await fetchHashKeyItem(result.key); + expect(itemFromDB?.createdAt).not.toBeUndefined(); + expect(itemFromDB?.createdAt).toEqual(itemFromDB?.updatedAt); + }, + { retries: 3 }, + ); }); describe('with a idOption prefix', () => { - it('item id should start with prefix', async () => { + it('item id should start with prefix with underscore', async () => { // ARRANGE - const item = await createTestKeyValueItem(); + const item = createTestKeyValueItem(); const prefix = 'itm_'; const repo = new KeyValueRepository({ tableName: TableName, @@ -90,11 +99,41 @@ describe('When creating item', () => { const { key } = await repo.create(item); testKeys.push(key); - await retry(async () => { - // ASSERT - const itemFromDB = await fetchHashKeyItem(key); - expect(itemFromDB?.[KeyName]).toStartWith(prefix); - }, { retries: 3 }); + await retry( + async () => { + // ASSERT + const itemFromDB = await fetchHashKeyItem(key); + expect(itemFromDB?.[KeyName]).toStartWith(prefix); + }, + { retries: 3 }, + ); + }); + + it('item id should start with prefix with pound', async () => { + // ARRANGE + const item = createTestKeyValueItem(); + const prefix = 'itm#'; + const repo = new KeyValueRepository({ + tableName: TableName, + keyName: KeyName, + idOptions: { + prefix, + }, + documentClient, + }); + + // ACT + const { key } = await repo.create(item); + testKeys.push(key); + + await retry( + async () => { + // ASSERT + const itemFromDB = await fetchHashKeyItem(key); + expect(itemFromDB?.[KeyName]).toStartWith(prefix); + }, + { retries: 3 }, + ); }); }); });