Skip to content

Commit 8b0660e

Browse files
committed
backend api unit test pass
1 parent 6f6d4de commit 8b0660e

File tree

9 files changed

+9
-74
lines changed

9 files changed

+9
-74
lines changed

infrastructure/terraform/modules/backend-api/module_delete_template_lambda.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ data "aws_iam_policy_document" "delete_template_lambda_policy" {
4848
]
4949
}
5050

51-
statement {
52-
sid = "AllowDynamoGSIAccess"
53-
effect = "Allow"
54-
55-
actions = [
56-
"dynamodb:Query",
57-
]
58-
59-
resources = [
60-
"${aws_dynamodb_table.templates.arn}/index/QueryById",
61-
]
62-
}
63-
6451
statement {
6552
sid = "AllowKMSAccess"
6653
effect = "Allow"

infrastructure/terraform/modules/backend-api/module_get_template_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ data "aws_iam_policy_document" "get_template_lambda_policy" {
4040
effect = "Allow"
4141

4242
actions = [
43-
"dynamodb:BatchGetItem",
43+
"dynamodb:GetItem",
4444
]
4545

4646
resources = [

infrastructure/terraform/modules/backend-api/module_lambda_process_proof.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ data "aws_iam_policy_document" "process_proof" {
5151
]
5252
}
5353

54-
statement {
55-
sid = "AllowDynamoGSIAccess"
56-
effect = "Allow"
57-
58-
actions = [
59-
"dynamodb:Query",
60-
]
61-
62-
resources = [
63-
"${aws_dynamodb_table.templates.arn}/index/QueryById",
64-
]
65-
}
66-
6754
statement {
6855
sid = "AllowKMSAccess"
6956
effect = "Allow"

infrastructure/terraform/modules/backend-api/module_lambda_validate_letter_template_files.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ data "aws_iam_policy_document" "validate_letter_template_files" {
5555
effect = "Allow"
5656

5757
actions = [
58-
"dynamodb:BatchGetItem",
58+
"dynamodb:GetItem",
5959
"dynamodb:UpdateItem",
6060
]
6161

infrastructure/terraform/modules/backend-api/module_submit_template_lambda.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ data "aws_iam_policy_document" "submit_template_lambda_policy" {
4848
]
4949
}
5050

51-
statement {
52-
sid = "AllowDynamoGSIAccess"
53-
effect = "Allow"
54-
55-
actions = [
56-
"dynamodb:Query",
57-
]
58-
59-
resources = [
60-
"${aws_dynamodb_table.templates.arn}/index/QueryById",
61-
]
62-
}
63-
6451
statement {
6552
sid = "AllowKMSAccess"
6653
effect = "Allow"

infrastructure/terraform/modules/backend-api/module_update_template_lambda.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ data "aws_iam_policy_document" "update_template_lambda_policy" {
4848
]
4949
}
5050

51-
statement {
52-
sid = "AllowDynamoGSIAccess"
53-
effect = "Allow"
54-
55-
actions = [
56-
"dynamodb:Query",
57-
]
58-
59-
resources = [
60-
"${aws_dynamodb_table.templates.arn}/index/QueryById",
61-
]
62-
}
63-
6451
statement {
6552
sid = "AllowKMSAccess"
6653
effect = "Allow"

infrastructure/terraform/modules/backend-api/module_upload_letter_template_lambda.tf

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,7 @@ data "aws_iam_policy_document" "upload_letter_template_lambda_policy" {
4848
aws_dynamodb_table.templates.arn,
4949
]
5050
}
51-
52-
statement {
53-
sid = "AllowDynamoGSIAccess"
54-
effect = "Allow"
55-
56-
actions = [
57-
"dynamodb:Query",
58-
]
59-
60-
resources = [
61-
"${aws_dynamodb_table.templates.arn}/index/QueryById",
62-
]
63-
}
64-
51+
6552
statement {
6653
sid = "AllowKMSAccess"
6754
effect = "Allow"

lambdas/backend-api/src/__tests__/templates/infra/template-repository.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'aws-sdk-client-mock-jest';
22
import { randomUUID } from 'node:crypto';
33
import {
4-
BatchGetCommand,
54
DynamoDBDocumentClient,
65
GetCommand,
76
PutCommand,
@@ -1162,20 +1161,20 @@ describe('templateRepository', () => {
11621161
expect(owner).toEqual('template-owner');
11631162
});
11641163

1165-
it('gets clientId', async () => {
1164+
it('errors if owner does not start with CLIENT#', async () => {
11661165
const { templateRepository, mocks } = setup();
11671166

11681167
mocks.ddbDocClient.on(QueryCommand).resolves({
11691168
Items: [
11701169
{
1171-
owner: 'CLIENT#template-owner',
1170+
owner: 'NOTCLIENT#template-owner',
11721171
},
11731172
],
11741173
});
11751174

1176-
const owner = await templateRepository.getClientId('template-id');
1177-
1178-
expect(owner).toEqual('template-owner');
1175+
await expect(() =>
1176+
templateRepository.getClientId('template-id')
1177+
).rejects.toThrow('Unexpected owner format NOTCLIENT#template-owner');
11791178
});
11801179

11811180
it('errors when owner cannot be found', async () => {

lambdas/backend-api/src/templates/infra/template-repository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export class TemplateRepository {
311311
const { Items = [], LastEvaluatedKey } = await this.client.send(
312312
new QueryCommand(input)
313313
);
314+
314315
input.ExclusiveStartKey = LastEvaluatedKey;
315316
items.push(...(Items as DatabaseTemplate[]));
316317
} while (input.ExclusiveStartKey);

0 commit comments

Comments
 (0)