@remit/backend 0.0.124 → 0.0.125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { afterEach, describe, it } from "node:test";
|
|
3
3
|
import type { MailboxItem } from "@remit/data-ports";
|
|
4
|
+
import { BadRequestError } from "@remit/data-ports/errors";
|
|
4
5
|
import { MailboxSyncStatus } from "@remit/domain-enums";
|
|
5
6
|
import { UnconfirmedTrashMailboxError } from "@remit/mailbox-service";
|
|
6
7
|
import type { APIGatewayProxyEvent } from "aws-lambda";
|
|
@@ -11,7 +12,11 @@ import {
|
|
|
11
12
|
type RemitClient,
|
|
12
13
|
setClient,
|
|
13
14
|
} from "../service/data-client.js";
|
|
14
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
MailboxDetailOperations,
|
|
17
|
+
MailboxOperations,
|
|
18
|
+
TrashOperations,
|
|
19
|
+
} from "./mailbox.js";
|
|
15
20
|
|
|
16
21
|
const SUB = "cognito-sub-887";
|
|
17
22
|
const ACCOUNT_ID = "acc-887";
|
|
@@ -230,3 +235,46 @@ describe("MailboxDetailOperations_deleteMailbox — what it refuses (D4, D16)",
|
|
|
230
235
|
assert.deepEqual(deleted, ["mbx-1"]);
|
|
231
236
|
});
|
|
232
237
|
});
|
|
238
|
+
|
|
239
|
+
const createMailbox =
|
|
240
|
+
MailboxOperations.MailboxOperations_createMailbox as unknown as (
|
|
241
|
+
context: Context,
|
|
242
|
+
event: APIGatewayProxyEvent,
|
|
243
|
+
) => Promise<unknown>;
|
|
244
|
+
|
|
245
|
+
describe("MailboxOperations_createMailbox", () => {
|
|
246
|
+
afterEach(() => {
|
|
247
|
+
_resetForTest();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("refuses a path the account already has a folder at", async () => {
|
|
251
|
+
setClient({
|
|
252
|
+
account: {
|
|
253
|
+
get: async () => ({
|
|
254
|
+
accountId: ACCOUNT_ID,
|
|
255
|
+
accountConfigId: deriveAccountConfigId(SUB),
|
|
256
|
+
}),
|
|
257
|
+
},
|
|
258
|
+
mailboxQueue: {
|
|
259
|
+
createMailbox: async () => ({ outcome: "PathTaken" }),
|
|
260
|
+
},
|
|
261
|
+
} as unknown as RemitClient);
|
|
262
|
+
|
|
263
|
+
await assert.rejects(
|
|
264
|
+
createMailbox(
|
|
265
|
+
{
|
|
266
|
+
request: {
|
|
267
|
+
params: { accountId: ACCOUNT_ID },
|
|
268
|
+
requestBody: { namespaceType: "personal", fullPath: "Receipts" },
|
|
269
|
+
},
|
|
270
|
+
} as unknown as Context,
|
|
271
|
+
{
|
|
272
|
+
requestContext: { authorizer: { claims: { sub: SUB } } },
|
|
273
|
+
} as unknown as APIGatewayProxyEvent,
|
|
274
|
+
),
|
|
275
|
+
(error: unknown) =>
|
|
276
|
+
error instanceof BadRequestError &&
|
|
277
|
+
error.message === "A folder named “Receipts” is already there.",
|
|
278
|
+
);
|
|
279
|
+
});
|
|
280
|
+
});
|
package/src/handlers/mailbox.ts
CHANGED
|
@@ -402,7 +402,7 @@ export const MailboxOperations: Record<
|
|
|
402
402
|
const account = await client.account.get(accountId);
|
|
403
403
|
assertAccountOwnership(account, accountConfigId, "act");
|
|
404
404
|
|
|
405
|
-
const
|
|
405
|
+
const created = await client.mailboxQueue.createMailbox(
|
|
406
406
|
{
|
|
407
407
|
accountId,
|
|
408
408
|
namespaceType: namespaceType as "personal" | "other_users" | "shared",
|
|
@@ -423,8 +423,13 @@ export const MailboxOperations: Record<
|
|
|
423
423
|
accountId,
|
|
424
424
|
true,
|
|
425
425
|
);
|
|
426
|
+
if (created.outcome === "PathTaken") {
|
|
427
|
+
throw new BadRequestError(
|
|
428
|
+
`A folder named “${fullPath}” is already there.`,
|
|
429
|
+
);
|
|
430
|
+
}
|
|
426
431
|
|
|
427
|
-
return toMailboxResponse(mailbox);
|
|
432
|
+
return toMailboxResponse(created.mailbox);
|
|
428
433
|
},
|
|
429
434
|
};
|
|
430
435
|
|