|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { validate, ids } from "../generated/lexicons.js"; |
| 3 | +import * as Organization from "../generated/types/app/certified/actor/organization.js"; |
| 4 | + |
| 5 | +describe("app.certified.actor.organization", () => { |
| 6 | + it("should accept a minimal valid record (only required createdAt)", () => { |
| 7 | + const result = Organization.validateMain({ |
| 8 | + $type: ids.AppCertifiedActorOrganization, |
| 9 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 10 | + }); |
| 11 | + expect(result.success).toBe(true); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should accept record with visibility set to 'public'", () => { |
| 15 | + const result = Organization.validateMain({ |
| 16 | + $type: ids.AppCertifiedActorOrganization, |
| 17 | + visibility: "public", |
| 18 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 19 | + }); |
| 20 | + expect(result.success).toBe(true); |
| 21 | + if (result.success) { |
| 22 | + expect(result.value.visibility).toBe("public"); |
| 23 | + } |
| 24 | + }); |
| 25 | + |
| 26 | + it("should accept record with visibility set to 'unlisted'", () => { |
| 27 | + const result = Organization.validateMain({ |
| 28 | + $type: ids.AppCertifiedActorOrganization, |
| 29 | + visibility: "unlisted", |
| 30 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 31 | + }); |
| 32 | + expect(result.success).toBe(true); |
| 33 | + if (result.success) { |
| 34 | + expect(result.value.visibility).toBe("unlisted"); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + it("should accept record with inline longDescription (descriptionString)", () => { |
| 39 | + const result = Organization.validateMain({ |
| 40 | + $type: ids.AppCertifiedActorOrganization, |
| 41 | + longDescription: { |
| 42 | + $type: "org.hypercerts.defs#descriptionString", |
| 43 | + value: "Our mission is to restore mangrove ecosystems worldwide.", |
| 44 | + }, |
| 45 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 46 | + }); |
| 47 | + expect(result.success).toBe(true); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should accept record with all optional fields populated", () => { |
| 51 | + const result = Organization.validateMain({ |
| 52 | + $type: ids.AppCertifiedActorOrganization, |
| 53 | + organizationType: ["nonprofit", "ngo"], |
| 54 | + urls: [{ url: "https://example.org", label: "Website" }], |
| 55 | + foundedDate: "2010-01-01T00:00:00.000Z", |
| 56 | + longDescription: { |
| 57 | + $type: "org.hypercerts.defs#descriptionString", |
| 58 | + value: "Full org description in markdown.", |
| 59 | + }, |
| 60 | + visibility: "public", |
| 61 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 62 | + }); |
| 63 | + expect(result.success).toBe(true); |
| 64 | + }); |
| 65 | + |
| 66 | + it("should reject record missing required createdAt", () => { |
| 67 | + const result = validate( |
| 68 | + { organizationType: ["nonprofit"] }, |
| 69 | + ids.AppCertifiedActorOrganization, |
| 70 | + "main", |
| 71 | + false, |
| 72 | + ); |
| 73 | + expect(result.success).toBe(false); |
| 74 | + if (!result.success) { |
| 75 | + expect(result.error).toBeDefined(); |
| 76 | + } |
| 77 | + }); |
| 78 | + |
| 79 | + it("should reject record with invalid createdAt format", () => { |
| 80 | + const result = validate( |
| 81 | + { |
| 82 | + createdAt: "not-a-datetime", |
| 83 | + }, |
| 84 | + ids.AppCertifiedActorOrganization, |
| 85 | + "main", |
| 86 | + false, |
| 87 | + ); |
| 88 | + expect(result.success).toBe(false); |
| 89 | + }); |
| 90 | +}); |
0 commit comments