|
| 1 | +import { addEdit } from "../scripts/add-edit.ss" |
| 2 | + |
| 3 | +testIdentity = (): { bundle: string } => { |
| 4 | + sign = generateEd25519KeyPair() |
| 5 | + enc = generateX25519KeyPair() |
| 6 | + raw = { id: "test-identity", signing: { privateKey: sign.privateKey }, encryption: { privateKey: enc.privateKey } } |
| 7 | + json = jsonStringify({ value: raw }) |
| 8 | + encoded = base64urlEncode({ text: json.text }) |
| 9 | + return { bundle: encoded.encoded } |
| 10 | +} |
| 11 | + |
| 12 | +mockHttpRequest = (host: string, method: string, path: string, headers: { x_timestamp: string }): { status: number, body: string } => { |
| 13 | + isEditPath = stringContains({ haystack: path, needle: "/edits" }) |
| 14 | + if (isEditPath) { |
| 15 | + return { status: 201, body: "{\"edit\":{\"id\":\"mock-edit-id\"}}" } |
| 16 | + } |
| 17 | + return { status: 200, body: "{\"document\":{\"id\":\"mock-doc-id\",\"snapshotSequenceNumber\":0}}" } |
| 18 | +} |
| 19 | + |
| 20 | +testAddEdit = (): { ok: boolean } => { |
| 21 | + id = testIdentity() |
| 22 | + newSnapshot = jsonStringify({ value: { kind: "doc", title: "Updated", content: "**Hello** from [link](https://example.com)" } }) |
| 23 | + result = override(addEdit, { httpRequest: mockHttpRequest })("mock-doc-id", "mock-key-123", newSnapshot.text, id.bundle) |
| 24 | + assert({ condition: result.status == 201, message: stringConcat({ parts: ["Expected 201, got ", jsonStringify({ value: result.status }).text] }).result }) |
| 25 | + assert({ condition: result.sequenceNumber == 1, message: stringConcat({ parts: ["Expected seq 1, got ", jsonStringify({ value: result.sequenceNumber }).text] }).result }) |
| 26 | + return { ok: true } |
| 27 | +} |
0 commit comments