@remit/drizzle-service 0.0.85 → 0.0.86
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 +1 -1
- package/src/account-synced-services-migration.sqlite.test.ts +49 -0
- package/src/repos/account.conformance.sqlite.test.ts +23 -0
- package/src/repos/cascade-delete.sqlite.test.ts +1 -0
- package/src/repos/cascade-delete.test.ts +1 -0
- package/src/repos/i4-account.ts +5 -1
- package/src/repos/i4-address-junk-move.sqlite.test.ts +2 -2
- package/src/repos/i4-mailbox-special-use.sqlite.test.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import { AccountService } from "@remit/domain-enums";
|
|
4
|
+
import Database from "better-sqlite3";
|
|
5
|
+
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
6
|
+
import { AccountRepo } from "./repos/i4-account.js";
|
|
7
|
+
import { accountTable } from "./schema.js";
|
|
8
|
+
import {
|
|
9
|
+
applyMigration,
|
|
10
|
+
migrationJournal,
|
|
11
|
+
} from "./test-shipped-sqlite-schema.js";
|
|
12
|
+
|
|
13
|
+
const MIGRATION = "0029_account_synced_services";
|
|
14
|
+
|
|
15
|
+
const atPredecessor = (): Database.Database => {
|
|
16
|
+
const sqlite = new Database(":memory:");
|
|
17
|
+
for (const entry of migrationJournal()) {
|
|
18
|
+
if (entry.tag === MIGRATION) return sqlite;
|
|
19
|
+
applyMigration(sqlite, entry.tag);
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`${MIGRATION} is not in the journal`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe("an account written before the service selection existed", () => {
|
|
25
|
+
test("comes out of the migration syncing mail only", async () => {
|
|
26
|
+
const sqlite = atPredecessor();
|
|
27
|
+
sqlite
|
|
28
|
+
.prepare(
|
|
29
|
+
`INSERT INTO account (
|
|
30
|
+
account_id, account_config_id, username, email, auth_type,
|
|
31
|
+
imap_host, imap_port, imap_tls, imap_start_tls, smtp_port,
|
|
32
|
+
is_active, connection_state, created_at, updated_at
|
|
33
|
+
) VALUES ('existing', 'config', 'person', 'person@example.com',
|
|
34
|
+
'password', 'imap.example.com', 993, 1, 0, 587, 1,
|
|
35
|
+
'not_authenticated', 0, 0)`,
|
|
36
|
+
)
|
|
37
|
+
.run();
|
|
38
|
+
|
|
39
|
+
applyMigration(sqlite, MIGRATION);
|
|
40
|
+
|
|
41
|
+
const repo = new AccountRepo(
|
|
42
|
+
drizzle(sqlite, { schema: { accounts: accountTable } }) as never,
|
|
43
|
+
);
|
|
44
|
+
assert.deepEqual((await repo.get("existing")).syncedServices, [
|
|
45
|
+
AccountService.Mail,
|
|
46
|
+
]);
|
|
47
|
+
sqlite.close();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { accountRepositoryConformance } from "@remit/data-ports/conformance";
|
|
2
|
+
import { NotFoundError } from "../error.js";
|
|
3
|
+
import { randomId } from "../id.js";
|
|
4
|
+
import { accountTable } from "../schema.js";
|
|
5
|
+
import { createSqliteTestDb } from "../test-db-sqlite.js";
|
|
6
|
+
import { AccountRepo } from "./i4-account.js";
|
|
7
|
+
|
|
8
|
+
let close: (() => Promise<void>) | undefined;
|
|
9
|
+
|
|
10
|
+
accountRepositoryConformance({
|
|
11
|
+
async createRepository() {
|
|
12
|
+
const { db, close: closeDb } = await createSqliteTestDb({
|
|
13
|
+
accounts: accountTable,
|
|
14
|
+
});
|
|
15
|
+
close = closeDb;
|
|
16
|
+
return new AccountRepo(db as never);
|
|
17
|
+
},
|
|
18
|
+
teardown: async () => {
|
|
19
|
+
await close?.();
|
|
20
|
+
},
|
|
21
|
+
makeId: () => randomId(),
|
|
22
|
+
isNotFoundError: (error) => error instanceof NotFoundError,
|
|
23
|
+
});
|
package/src/repos/i4-account.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
ResultList,
|
|
8
8
|
UpdateAccountInput,
|
|
9
9
|
} from "@remit/data-ports";
|
|
10
|
-
import { SyncPhase } from "@remit/domain-enums";
|
|
10
|
+
import { AccountService, SyncPhase } from "@remit/domain-enums";
|
|
11
11
|
import { and, asc, eq, gt, inArray, or, sql } from "drizzle-orm";
|
|
12
12
|
import type { Db } from "../db.js";
|
|
13
13
|
import { NotFoundError } from "../error.js";
|
|
@@ -39,6 +39,7 @@ export function rowToAccount(
|
|
|
39
39
|
username: row.username,
|
|
40
40
|
email: row.email,
|
|
41
41
|
authType: row.authType as AccountItem["authType"],
|
|
42
|
+
syncedServices: row.syncedServices as AccountItem["syncedServices"],
|
|
42
43
|
passwordHash: row.passwordHash ?? undefined,
|
|
43
44
|
oauthRefreshTokenHash: row.oauthRefreshTokenHash ?? undefined,
|
|
44
45
|
oauthTokenUpdatedAt: row.oauthTokenUpdatedAt ?? undefined,
|
|
@@ -81,6 +82,7 @@ export class AccountRepo implements IAccountRepository {
|
|
|
81
82
|
username: input.username,
|
|
82
83
|
email: input.email,
|
|
83
84
|
authType: input.authType ?? "password",
|
|
85
|
+
syncedServices: input.syncedServices ?? [AccountService.Mail],
|
|
84
86
|
passwordHash: input.passwordHash,
|
|
85
87
|
oauthRefreshTokenHash: input.oauthRefreshTokenHash,
|
|
86
88
|
oauthTokenUpdatedAt: input.oauthTokenUpdatedAt,
|
|
@@ -144,6 +146,8 @@ export class AccountRepo implements IAccountRepository {
|
|
|
144
146
|
if (input.username !== undefined) updates.username = input.username;
|
|
145
147
|
if (input.email !== undefined) updates.email = input.email;
|
|
146
148
|
if (input.authType !== undefined) updates.authType = input.authType;
|
|
149
|
+
if (input.syncedServices !== undefined)
|
|
150
|
+
updates.syncedServices = input.syncedServices;
|
|
147
151
|
if (input.passwordHash !== undefined)
|
|
148
152
|
updates.passwordHash = input.passwordHash;
|
|
149
153
|
if (input.oauthRefreshTokenHash !== undefined)
|
|
@@ -20,9 +20,9 @@ describe("reconciling one message's addresses at the moment it moves", () => {
|
|
|
20
20
|
`INSERT OR IGNORE INTO account (
|
|
21
21
|
account_id, account_config_id, username, email, imap_host,
|
|
22
22
|
imap_port, imap_tls, imap_start_tls, smtp_port, is_active,
|
|
23
|
-
connection_state, created_at, updated_at
|
|
23
|
+
connection_state, synced_services, created_at, updated_at
|
|
24
24
|
) VALUES (?, ?, 'user', 'user@example.com', 'imap.example.com',
|
|
25
|
-
993, 1, 0, 465, 1, 'disconnected', 0, 0)`,
|
|
25
|
+
993, 1, 0, 465, 1, 'disconnected', '["Mail"]', 0, 0)`,
|
|
26
26
|
)
|
|
27
27
|
.run(accountId, CONFIG);
|
|
28
28
|
};
|