Skip to content

Commit e9608dc

Browse files
committed
set lock for one month to "finalise"
1 parent 024057a commit e9608dc

File tree

6 files changed

+24
-42
lines changed

6 files changed

+24
-42
lines changed

infrastructure/terraform/components/acct/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ variable "letter_suppliers" {
110110
enable_polling = bool
111111
default_supplier = optional(bool)
112112
}))
113-
description = "Letter suppliers enabled in the environment"
113+
description = "Letter suppliers enabled in the account (across all environments)"
114114
default = {}
115115
}

infrastructure/terraform/components/sandbox/variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ variable "default_tags" {
4747
default = {}
4848
}
4949

50-
variable "parent_acct_environment" {
51-
type = string
52-
description = "Name of the environment responsible for the acct resources used"
53-
default = "main"
54-
}
55-
5650
##
5751
# Variables specific to the "sandbox"component
5852
##

lambdas/sftp-letters/src/__tests__/infra/template-lock-repository.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ describe('TemplateLockRepository', () => {
4141
'#sftpSendLockTime': 'sftpSendLockTime',
4242
},
4343
ExpressionAttributeValues: {
44-
':condition_1_sftpSendLockTime': 0,
4544
':condition_2_sftpSendLockTime': mockDate.getTime() + sendLockTtlMs,
4645
':updatedAt': expect.stringMatching(isoDateRegExp),
4746
':sftpSendLockTime': mockDate.getTime(),
4847
},
4948
ConditionExpression:
50-
'#sftpSendLockTime <> :condition_1_sftpSendLockTime AND #sftpSendLockTime > :condition_2_sftpSendLockTime OR attribute_not_exists (#sftpSendLockTime)',
49+
'attribute_not_exists (#sftpSendLockTime) OR #sftpSendLockTime > :condition_2_sftpSendLockTime',
5150
Key: {
5251
id: templateId,
5352
owner,
@@ -98,8 +97,8 @@ describe('TemplateLockRepository', () => {
9897
'#sftpSendLockTime': 'sftpSendLockTime',
9998
},
10099
ExpressionAttributeValues: {
101-
':updatedAt': expect.stringMatching(isoDateRegExp),
102-
':sftpSendLockTime': 0,
100+
':updatedAt': expect.any(String),
101+
':sftpSendLockTime': mockDate.getTime() + 2_592_000_000,
103102
},
104103
Key: {
105104
id: templateId,

lambdas/sftp-letters/src/infra/template-lock-repository.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ConditionalCheckFailedException } from '@aws-sdk/client-dynamodb';
22
import { DynamoDBDocumentClient, UpdateCommand } from '@aws-sdk/lib-dynamodb';
33
import { TemplateUpdateBuilder } from 'nhs-notify-entity-update-command-builder';
44

5+
const THIRTY_DAYS_MS = 2_592_000_000;
6+
57
export class TemplateLockRepository {
68
constructor(
79
private readonly client: DynamoDBDocumentClient,
@@ -14,7 +16,7 @@ export class TemplateLockRepository {
1416
const time = this.getDate().getTime();
1517

1618
const update = new TemplateUpdateBuilder(this.templatesTableName, owner, id)
17-
.setLockTimeConditionally('sftpSendLockTime', time, time + this.lockTtl)
19+
.setLockTime('sftpSendLockTime', time, time + this.lockTtl)
1820
.build();
1921

2022
try {
@@ -30,8 +32,10 @@ export class TemplateLockRepository {
3032
}
3133

3234
async finaliseLock(owner: string, id: string) {
35+
const time = this.getDate().getTime();
36+
3337
const update = new TemplateUpdateBuilder(this.templatesTableName, owner, id)
34-
.setLockTimeUnconditionally('sftpSendLockTime', 0)
38+
.setLockTimeUnconditional('sftpSendLockTime', time + THIRTY_DAYS_MS)
3539
.build();
3640

3741
return await this.client.send(new UpdateCommand(update));

utils/entity-update-command-builder/src/__tests__/template-update-builder.test.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ beforeAll(() => {
1111
jest.setSystemTime(mockDate);
1212
});
1313

14-
describe('TemplateBuilder', () => {
14+
describe('TemplateUpdateBuilder', () => {
1515
describe('build', () => {
1616
test('after initialisation returns default update (updatedAt)', () => {
1717
const builder = new TemplateUpdateBuilder(
@@ -167,29 +167,25 @@ describe('TemplateBuilder', () => {
167167
});
168168
});
169169

170-
describe('setLockTimeConditionally', () => {
171-
test('sets lock time if no lock exists, or lock is not finalised (set to zero)', () => {
170+
describe('setLockTime', () => {
171+
test('sets lock time if no lock exists', () => {
172172
const builder = new TemplateUpdateBuilder(
173173
mockTableName,
174174
mockOwner,
175175
mockId
176176
);
177177

178-
const res = builder
179-
.setLockTimeConditionally('sftpSendLockTime', 500)
180-
.build();
178+
const res = builder.setLockTime('sftpSendLockTime', 500).build();
181179

182180
expect(res).toEqual({
183-
ConditionExpression:
184-
'#sftpSendLockTime <> :condition_1_sftpSendLockTime OR attribute_not_exists (#sftpSendLockTime)',
181+
ConditionExpression: 'attribute_not_exists (#sftpSendLockTime)',
185182
ExpressionAttributeNames: {
186183
'#sftpSendLockTime': 'sftpSendLockTime',
187184
'#updatedAt': 'updatedAt',
188185
},
189186
ExpressionAttributeValues: {
190187
':sftpSendLockTime': 500,
191188
':updatedAt': '2025-01-01T09:00:00.000Z',
192-
':condition_1_sftpSendLockTime': 0,
193189
},
194190
Key: {
195191
id: 'Hello2',
@@ -208,19 +204,16 @@ describe('TemplateBuilder', () => {
208204
mockId
209205
);
210206

211-
const res = builder
212-
.setLockTimeConditionally('sftpSendLockTime', 1000, 1500)
213-
.build();
207+
const res = builder.setLockTime('sftpSendLockTime', 1000, 1500).build();
214208

215209
expect(res).toEqual({
216210
ConditionExpression:
217-
'#sftpSendLockTime <> :condition_1_sftpSendLockTime AND #sftpSendLockTime > :condition_2_sftpSendLockTime OR attribute_not_exists (#sftpSendLockTime)',
211+
'attribute_not_exists (#sftpSendLockTime) OR #sftpSendLockTime > :condition_2_sftpSendLockTime',
218212
ExpressionAttributeNames: {
219213
'#sftpSendLockTime': 'sftpSendLockTime',
220214
'#updatedAt': 'updatedAt',
221215
},
222216
ExpressionAttributeValues: {
223-
':condition_1_sftpSendLockTime': 0,
224217
':condition_2_sftpSendLockTime': 1500,
225218
':sftpSendLockTime': 1000,
226219
':updatedAt': '2025-01-01T09:00:00.000Z',
@@ -236,7 +229,7 @@ describe('TemplateBuilder', () => {
236229
});
237230
});
238231

239-
describe('setLockTimeUnconditionally', () => {
232+
describe('setLockTimeUnconditional', () => {
240233
test('sets lock time without conditions', () => {
241234
const builder = new TemplateUpdateBuilder(
242235
mockTableName,
@@ -245,7 +238,7 @@ describe('TemplateBuilder', () => {
245238
);
246239

247240
const res = builder
248-
.setLockTimeUnconditionally('sftpSendLockTime', 500)
241+
.setLockTimeUnconditional('sftpSendLockTime', 1)
249242
.build();
250243

251244
expect(res).toEqual({
@@ -254,7 +247,7 @@ describe('TemplateBuilder', () => {
254247
'#updatedAt': 'updatedAt',
255248
},
256249
ExpressionAttributeValues: {
257-
':sftpSendLockTime': 500,
250+
':sftpSendLockTime': 1,
258251
':updatedAt': '2025-01-01T09:00:00.000Z',
259252
},
260253
Key: {

utils/entity-update-command-builder/src/template-update-builder.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,23 @@ export class TemplateUpdateBuilder extends EntityUpdateBuilder<MergedTemplate> {
3434
return this;
3535
}
3636

37-
setLockTimeConditionally(
37+
setLockTime(
3838
lockField: 'sftpSendLockTime',
3939
timeMs: number,
4040
lockExpiryTimeMs?: number
4141
) {
4242
this.updateBuilder
4343
.setValue(lockField, timeMs)
44-
.andCondition(lockField, 0, '<>');
44+
.fnCondition(lockField, null, 'attribute_not_exists');
4545

4646
if (lockExpiryTimeMs) {
47-
this.updateBuilder.andCondition(lockField, lockExpiryTimeMs, '>');
47+
this.updateBuilder.orCondition(lockField, lockExpiryTimeMs, '>');
4848
}
4949

50-
this.updateBuilder.fnCondition(
51-
lockField,
52-
null,
53-
'attribute_not_exists',
54-
false,
55-
'OR'
56-
);
57-
5850
return this;
5951
}
6052

61-
setLockTimeUnconditionally(lockField: 'sftpSendLockTime', timeMs: number) {
53+
setLockTimeUnconditional(lockField: 'sftpSendLockTime', timeMs: number) {
6254
this.updateBuilder.setValue(lockField, timeMs);
6355

6456
return this;

0 commit comments

Comments
 (0)