Skip to content

Commit e9f4473

Browse files
committed
unit tests added
1 parent 91e63a4 commit e9f4473

2 files changed

Lines changed: 190 additions & 0 deletions

File tree

test/unit/email.test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { DataFactory, Parser, Store } from "n3"
2+
import assert from "node:assert"
3+
import { describe, it } from "node:test"
4+
5+
import { Email } from "@solid/object";
6+
7+
describe("Email tests", () => {
8+
9+
const sampleRDF = `
10+
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
11+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
12+
13+
<https://example.org/person/1>
14+
a vcard:Individual ;
15+
vcard:fn "Alice" ;
16+
vcard:hasEmail <https://example.org/email/1> .
17+
18+
<https://example.org/email/1>
19+
a vcard:Email ;
20+
vcard:value "alice@example.org" ;
21+
rdf:type vcard:Work .
22+
`;
23+
24+
it("should parse and retrieve email address", () => {
25+
const store = new Store()
26+
store.addQuads(new Parser().parse(sampleRDF))
27+
28+
const email = new Email(
29+
DataFactory.namedNode("https://example.org/email/1"),
30+
store,
31+
DataFactory
32+
)
33+
34+
assert.equal(email.emailAddress, "alice@example.org")
35+
assert.equal(typeof email.emailAddress, "string")
36+
})
37+
38+
it("should allow setting email address", () => {
39+
const store = new Store()
40+
store.addQuads(new Parser().parse(sampleRDF))
41+
42+
const email = new Email(
43+
DataFactory.namedNode("https://example.org/email/1"),
44+
store,
45+
DataFactory
46+
)
47+
48+
email.emailAddress = "bob@example.org"
49+
50+
assert.equal(email.emailAddress, "bob@example.org")
51+
})
52+
53+
it("should parse and retrieve email type", () => {
54+
const store = new Store()
55+
store.addQuads(new Parser().parse(sampleRDF))
56+
57+
const email = new Email(
58+
DataFactory.namedNode("https://example.org/email/1"),
59+
store,
60+
DataFactory
61+
)
62+
63+
const emailType = DataFactory.namedNode("http://www.w3.org/2006/vcard/ns#Home")
64+
65+
assert.ok(emailType !== undefined)
66+
assert.equal(typeof emailType, "object")
67+
assert.equal(emailType.value, "http://www.w3.org/2006/vcard/ns#Home")
68+
})
69+
70+
it("should allow setting email type", () => {
71+
const store = new Store()
72+
73+
const email = new Email(
74+
DataFactory.namedNode("https://example.org/email/2"),
75+
store,
76+
DataFactory
77+
)
78+
79+
email.emailAddress = "test@example.org"
80+
email.emailType = "http://www.w3.org/2006/vcard/ns#Home"
81+
82+
assert.equal(email.emailType, "http://www.w3.org/2006/vcard/ns#Home")
83+
})
84+
85+
})

test/unit/telephone.test.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { DataFactory, Parser, Store } from "n3"
2+
import assert from "node:assert"
3+
import { describe, it } from "node:test"
4+
5+
import { Telephone } from "@solid/object";
6+
7+
describe("Telephone tests", () => {
8+
9+
const sampleRDF = `
10+
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
11+
12+
<https://example.org/person/1>
13+
a vcard:Individual ;
14+
vcard:fn "Alice" ;
15+
vcard:hasTelephone <https://example.org/phone/1> .
16+
17+
<https://example.org/phone/1>
18+
a vcard:Telephone ;
19+
vcard:hasValue "+1234567890" ;
20+
vcard:TelephoneType vcard:Cell .
21+
`;
22+
23+
it("should parse and retrieve phone number", () => {
24+
const store = new Store()
25+
store.addQuads(new Parser().parse(sampleRDF))
26+
27+
const telephone = new Telephone(
28+
DataFactory.namedNode("https://example.org/phone/1"),
29+
store,
30+
DataFactory
31+
)
32+
33+
assert.equal(telephone.phoneNumber, "+1234567890")
34+
assert.equal(typeof telephone.phoneNumber, "string")
35+
})
36+
37+
it("should allow setting phone number", () => {
38+
const store = new Store()
39+
store.addQuads(new Parser().parse(sampleRDF))
40+
41+
const telephone = new Telephone(
42+
DataFactory.namedNode("https://example.org/phone/1"),
43+
store,
44+
DataFactory
45+
)
46+
47+
telephone.phoneNumber = "+0987654321"
48+
49+
assert.equal(telephone.phoneNumber, "+0987654321")
50+
})
51+
52+
it("should parse and retrieve phone type", () => {
53+
const store = new Store()
54+
store.addQuads(new Parser().parse(sampleRDF))
55+
56+
const telephone = new Telephone(
57+
DataFactory.namedNode("https://example.org/phone/1"),
58+
store,
59+
DataFactory
60+
)
61+
62+
const phoneType = telephone.phoneType
63+
64+
assert.ok(phoneType !== undefined)
65+
assert.equal(typeof phoneType, "string")
66+
assert.equal(phoneType, "http://www.w3.org/2006/vcard/ns#Cell")
67+
})
68+
69+
it("should allow setting phone type", () => {
70+
const store = new Store()
71+
72+
const telephone = new Telephone(
73+
DataFactory.namedNode("https://example.org/phone/2"),
74+
store,
75+
DataFactory
76+
)
77+
78+
telephone.phoneNumber = "+1112223333"
79+
telephone.phoneType = "http://www.w3.org/2006/vcard/ns#Car"
80+
81+
assert.equal(telephone.phoneType, "http://www.w3.org/2006/vcard/ns#Car")
82+
})
83+
84+
it("should throw when phone number is missing", () => {
85+
const noPhoneRDF = `
86+
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
87+
88+
<https://example.org/phone/empty>
89+
a vcard:Telephone .
90+
`
91+
const store = new Store()
92+
store.addQuads(new Parser().parse(noPhoneRDF))
93+
94+
const telephone = new Telephone(
95+
DataFactory.namedNode("https://example.org/phone/empty"),
96+
store,
97+
DataFactory
98+
)
99+
100+
assert.throws(() => {
101+
telephone.phoneNumber
102+
})
103+
})
104+
105+
})

0 commit comments

Comments
 (0)