Skip to content

Commit ba1aeb6

Browse files
authored
test(client-dynamodb): e2e test for type registry based error handling (#7486)
1 parent 3d7ac16 commit ba1aeb6

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

clients/client-dynamodb/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
14-
"generate:client": "node ../../scripts/generate-clients/single-service --solo dynamodb"
14+
"generate:client": "node ../../scripts/generate-clients/single-service --solo dynamodb",
15+
"test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts",
16+
"test:e2e:watch": "yarn g:vitest watch -c vitest.config.e2e.mts"
1517
},
1618
"main": "./dist-cjs/index.js",
1719
"types": "./dist-types/index.d.ts",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { DynamoDB, ResourceNotFoundException } from "@aws-sdk/client-dynamodb";
2+
import { TypeRegistry } from "@smithy/core/schema";
3+
import { StaticErrorSchema } from "@smithy/types";
4+
import { describe, expect, test as it } from "vitest";
5+
6+
describe(DynamoDB.name, () => {
7+
const ddb = new DynamoDB({
8+
region: "us-west-2",
9+
});
10+
11+
it("throws an error when table is not found", async () => {
12+
const error = await ddb
13+
.describeTable({
14+
TableName: "DynamoDB",
15+
})
16+
.catch((e) => e);
17+
18+
delete error.$response;
19+
20+
expect(error).toMatchObject({
21+
message: "Requested resource not found: Table: DynamoDB not found",
22+
$fault: "client",
23+
$metadata: {
24+
attempts: 1,
25+
httpStatusCode: 400,
26+
},
27+
name: "ResourceNotFoundException",
28+
});
29+
30+
expect(error).toBeInstanceOf(ResourceNotFoundException);
31+
32+
const registry = TypeRegistry.for("com.amazonaws.dynamodb");
33+
const errorSchema = registry.getSchema("ResourceNotFoundException") as StaticErrorSchema;
34+
expect(errorSchema).toBeDefined();
35+
const errorCtor = registry.getErrorCtor(errorSchema);
36+
37+
expect(errorCtor).toBe(ResourceNotFoundException);
38+
});
39+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.browser.e2e.spec.ts"],
6+
include: ["**/*.e2e.spec.ts"],
7+
environment: "node",
8+
},
9+
mode: "development",
10+
});

0 commit comments

Comments
 (0)