UNPKG

vcard4

Version:

An RFC 6350 compliant JavaScript library for generating and parsing version 4.0 vCards. Can also generate RFC 6351 compliant XML vCards and RFC 7095 compliant jCards. TypeScript type declarations are provided.

76 lines (72 loc) 2.15 kB
import { ParameterValueType, URIType, IntegerType, } from "../../src/values/index.js"; import { MediatypeParameter } from "../../src/parameters/index.js"; import { KeyProperty } from "../../src/properties/index.js"; import { assert } from "chai"; describe("KeyProperty tests", () => { it("Accepts valid input", () => { assert.doesNotThrow( () => new KeyProperty( [ new MediatypeParameter( new ParameterValueType("application/pgp-keys") ), ], new URIType("ftp://example.com/keys/jdoe") ) ); }); it("Rejects invalid input", () => { assert.throws( () => new KeyProperty([new IntegerType(55)], new IntegerType(55)) ); assert.throws(() => new KeyProperty()); assert.throws(() => new KeyProperty(1)); assert.throws(() => new KeyProperty({})); assert.throws(() => new KeyProperty("James Bond")); }); it("Formats value properly", () => { assert.strictEqual( new KeyProperty( [ new MediatypeParameter( new ParameterValueType("application/pgp-keys") ), ], new URIType("ftp://example.com/keys/jdoe") ).repr(), "KEY;MEDIATYPE=application/pgp-keys:ftp://example.com/keys/jdoe" ); assert.strictEqual( new KeyProperty( [ new MediatypeParameter( new ParameterValueType("application/pgp-keys") ), ], new URIType("ftp://example.com/keys/jdoe") ).reprXML(), "<key><parameters><mediatype><text>application/pgp-keys</text></mediatype></parameters><uri>ftp://example.com/keys/jdoe</uri></key>" ); assert.deepEqual( new KeyProperty( [ new MediatypeParameter( new ParameterValueType("application/pgp-keys") ), ], new URIType("ftp://example.com/keys/jdoe") ).reprJSON(), [ "key", { mediatype: "application/pgp-keys" }, "uri", "ftp://example.com/keys/jdoe", ] ); }); });