|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { validate, ids } from "../generated/lexicons.js"; |
| 3 | +import * as CreatedVia from "../generated/types/app/certified/actor/createdVia.js"; |
| 4 | + |
| 5 | +describe("app.certified.actor.createdVia", () => { |
| 6 | + it("should accept a minimal valid record (required clientId and createdAt)", () => { |
| 7 | + const result = CreatedVia.validateMain({ |
| 8 | + $type: ids.AppCertifiedActorCreatedVia, |
| 9 | + clientId: "https://app.certified.one/oauth/client-metadata.json", |
| 10 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 11 | + }); |
| 12 | + expect(result.success).toBe(true); |
| 13 | + if (result.success) { |
| 14 | + expect(result.value.clientId).toBe( |
| 15 | + "https://app.certified.one/oauth/client-metadata.json", |
| 16 | + ); |
| 17 | + } |
| 18 | + }); |
| 19 | + |
| 20 | + it("should accept a record with inline signatures", () => { |
| 21 | + const result = CreatedVia.validateMain({ |
| 22 | + $type: ids.AppCertifiedActorCreatedVia, |
| 23 | + clientId: "https://app.certified.one/oauth/client-metadata.json", |
| 24 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 25 | + signatures: [ |
| 26 | + { |
| 27 | + $type: "app.certified.signature.defs#inline", |
| 28 | + signature: new Uint8Array([1, 2, 3]), |
| 29 | + key: "did:plc:abc123#atproto", |
| 30 | + }, |
| 31 | + ], |
| 32 | + }); |
| 33 | + expect(result.success).toBe(true); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should reject a record missing required clientId", () => { |
| 37 | + const result = validate( |
| 38 | + { createdAt: "2024-01-01T00:00:00.000Z" }, |
| 39 | + ids.AppCertifiedActorCreatedVia, |
| 40 | + "main", |
| 41 | + false, |
| 42 | + ); |
| 43 | + expect(result.success).toBe(false); |
| 44 | + if (!result.success) { |
| 45 | + expect(result.error).toBeDefined(); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + it("should reject a record missing required createdAt", () => { |
| 50 | + const result = validate( |
| 51 | + { clientId: "https://app.certified.one/oauth/client-metadata.json" }, |
| 52 | + ids.AppCertifiedActorCreatedVia, |
| 53 | + "main", |
| 54 | + false, |
| 55 | + ); |
| 56 | + expect(result.success).toBe(false); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should reject a record with a non-uri clientId", () => { |
| 60 | + const result = validate( |
| 61 | + { |
| 62 | + clientId: "not a uri", |
| 63 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 64 | + }, |
| 65 | + ids.AppCertifiedActorCreatedVia, |
| 66 | + "main", |
| 67 | + false, |
| 68 | + ); |
| 69 | + expect(result.success).toBe(false); |
| 70 | + }); |
| 71 | + |
| 72 | + it("should reject a record with an invalid createdAt format", () => { |
| 73 | + const result = validate( |
| 74 | + { |
| 75 | + clientId: "https://app.certified.one/oauth/client-metadata.json", |
| 76 | + createdAt: "not-a-datetime", |
| 77 | + }, |
| 78 | + ids.AppCertifiedActorCreatedVia, |
| 79 | + "main", |
| 80 | + false, |
| 81 | + ); |
| 82 | + expect(result.success).toBe(false); |
| 83 | + }); |
| 84 | +}); |
0 commit comments