-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts_spec.js
98 lines (67 loc) · 2.83 KB
/
contacts_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
describe("Contacts", function () {
var namespace = epdRoot.Contacts
, profile
, otherProfile;
beforeEach(function () {
profile = epdRoot.Object.clone(fixtures.profile());
if (!otherProfile) {
otherProfile = epdRoot.Generator.generate();
}
});
describe("#ids", function () {
it("should return an array including all contact ids", function () {
var ids = namespace.ids(profile);
expect(ids).toEqual([ fixtures.anotherProfile().id ]);
});
});
describe("#idsBySectionId", function () {
it("should return the full profiles of all contacts assigned to the given section", function () {
var ids = namespace.idsBySectionId(profile, "test");
expect(ids).toEqual([ fixtures.anotherProfile().id ]);
});
});
describe("#keysForContactId", function () {
it("should return the keys for the given contact", function () {
var keys = namespace.keysForContactId(profile, fixtures.anotherProfile().id);
expect(keys.test).toBeOfType("aesKey");
});
});
describe("#keyForContactIdAndSectionId", function () {
it("should return the key for the given contact and the given section id", function () {
var key = namespace.keyForContactIdAndSectionId(profile, fixtures.anotherProfile().id, "test");
expect(key).toBeOfType("aesKey");
});
});
describe("#add", function () {
it("should add the given profile to the contacts", function () {
profile = namespace.add(profile, otherProfile.id);
expect(namespace.ids(profile)).toContain(otherProfile.id);
});
it("should do nothing if the contact has been added before", function () {
profile = namespace.add(profile, fixtures.anotherProfile().id);
expect(namespace.ids(profile)).toEqual([ fixtures.anotherProfile().id ]);
});
it("should not add a sections key if the contact is the profile owner", function () {
profile = namespace.add(profile, profile.id);
expect(profile.contacts[ profile.id ].sections).toBeUndefined();
});
});
describe("#remove", function () {
it("should remove the given profile to the contacts", function () {
profile = namespace.remove(profile, fixtures.anotherProfile().id);
expect(namespace.ids(profile)).not.toContain(fixtures.anotherProfile().id);
});
});
describe("#ensureAdded", function () {
it("should add the given contact if missing", function () {
profile = namespace.ensureAdded(profile, [ otherProfile.id ]);
expect(namespace.ids(profile)).toContain(otherProfile.id);
});
});
describe("#ensureRemoved", function () {
it("should remove the given contact if existing", function () {
profile = namespace.ensureRemoved(profile, [ fixtures.anotherProfile().id ]);
expect(namespace.ids(profile)).not.toContain(fixtures.anotherProfile().id);
});
});
});