Skip to content

Commit bdb9110

Browse files
committed
Add tests for the wrapper types
1 parent 5c3bb49 commit bdb9110

File tree

1 file changed

+218
-0
lines changed

1 file changed

+218
-0
lines changed

tests/types.spec.ts

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import * as dgraph from "../src";
2+
import { b64ToStr, strToB64, strToU8, u8ToStr } from "../src/util";
3+
4+
const obj = { k1: "v1" };
5+
const setNquads = "_:alice <name> \"Alice\"";
6+
const delNquads = "<0x7569> * * .";
7+
8+
describe("types", () => {
9+
describe("Payload", () => {
10+
it("should set and get data", () => {
11+
const p = new dgraph.Payload();
12+
13+
p.setData(obj);
14+
let o = p.getData();
15+
expect(o).toEqual(obj);
16+
17+
p.setData(strToB64(JSON.stringify(obj)));
18+
o = p.getData();
19+
expect(o).toEqual(obj);
20+
21+
p.setData(strToU8(JSON.stringify(obj)));
22+
o = p.getData();
23+
expect(o).toEqual(obj);
24+
});
25+
26+
it("should get data as b64", () => {
27+
const p = new dgraph.Payload();
28+
p.setData(obj);
29+
30+
const b64 = p.getData_asB64();
31+
const o = JSON.parse(b64ToStr(b64));
32+
expect(o).toEqual(obj);
33+
});
34+
35+
it("should get data as u8", () => {
36+
const p = new dgraph.Payload();
37+
p.setData(obj);
38+
39+
const u8 = p.getData_asU8();
40+
const o = JSON.parse(u8ToStr(u8));
41+
expect(o).toEqual(obj);
42+
});
43+
});
44+
45+
describe("Response", () => {
46+
it("should set and get json", () => {
47+
const p = new dgraph.Response();
48+
49+
p.setJson(obj);
50+
let o = p.getJson();
51+
expect(o).toEqual(obj);
52+
53+
p.setJson(strToB64(JSON.stringify(obj)));
54+
o = p.getJson();
55+
expect(o).toEqual(obj);
56+
57+
p.setJson(strToU8(JSON.stringify(obj)));
58+
o = p.getJson();
59+
expect(o).toEqual(obj);
60+
});
61+
62+
it("should get json as b64", () => {
63+
const p = new dgraph.Response();
64+
p.setJson(obj);
65+
66+
const b64 = p.getJson_asB64();
67+
const o = JSON.parse(b64ToStr(b64));
68+
expect(o).toEqual(obj);
69+
});
70+
71+
it("should get json as u8", () => {
72+
const p = new dgraph.Response();
73+
p.setJson(obj);
74+
75+
const u8 = p.getJson_asU8();
76+
const o = JSON.parse(u8ToStr(u8));
77+
expect(o).toEqual(obj);
78+
});
79+
});
80+
81+
describe("Mutation", () => {
82+
it("should set and get setJson", () => {
83+
const p = new dgraph.Mutation();
84+
85+
p.setSetJson(obj);
86+
let o = p.getSetJson();
87+
expect(o).toEqual(obj);
88+
89+
p.setSetJson(strToB64(JSON.stringify(obj)));
90+
o = p.getSetJson();
91+
expect(o).toEqual(obj);
92+
93+
p.setSetJson(strToU8(JSON.stringify(obj)));
94+
o = p.getSetJson();
95+
expect(o).toEqual(obj);
96+
});
97+
98+
it("should get setJson as b64", () => {
99+
const p = new dgraph.Mutation();
100+
p.setSetJson(obj);
101+
102+
const b64 = p.getSetJson_asB64();
103+
const o = JSON.parse(b64ToStr(b64));
104+
expect(o).toEqual(obj);
105+
});
106+
107+
it("should get setJson as u8", () => {
108+
const p = new dgraph.Mutation();
109+
p.setSetJson(obj);
110+
111+
const u8 = p.getSetJson_asU8();
112+
const o = JSON.parse(u8ToStr(u8));
113+
expect(o).toEqual(obj);
114+
});
115+
116+
it("should set and get deleteJson", () => {
117+
const p = new dgraph.Mutation();
118+
119+
p.setDeleteJson(obj);
120+
let o = p.getDeleteJson();
121+
expect(o).toEqual(obj);
122+
123+
p.setDeleteJson(strToB64(JSON.stringify(obj)));
124+
o = p.getDeleteJson();
125+
expect(o).toEqual(obj);
126+
127+
p.setDeleteJson(strToU8(JSON.stringify(obj)));
128+
o = p.getDeleteJson();
129+
expect(o).toEqual(obj);
130+
});
131+
132+
it("should get deleteJson as b64", () => {
133+
const p = new dgraph.Mutation();
134+
p.setDeleteJson(obj);
135+
136+
const b64 = p.getDeleteJson_asB64();
137+
const o = JSON.parse(b64ToStr(b64));
138+
expect(o).toEqual(obj);
139+
});
140+
141+
it("should get deleteJson as u8", () => {
142+
const p = new dgraph.Mutation();
143+
p.setDeleteJson(obj);
144+
145+
const u8 = p.getDeleteJson_asU8();
146+
const o = JSON.parse(u8ToStr(u8));
147+
expect(o).toEqual(obj);
148+
});
149+
150+
it("should set and get setNquads", () => {
151+
const p = new dgraph.Mutation();
152+
153+
p.setSetNquads(setNquads);
154+
let nq = p.getSetNquads();
155+
expect(nq).toEqual(setNquads);
156+
157+
p.setSetNquads(strToB64(setNquads));
158+
nq = p.getSetNquads();
159+
expect(nq).toEqual(setNquads);
160+
161+
p.setSetNquads(strToU8(setNquads));
162+
nq = p.getSetNquads();
163+
expect(nq).toEqual(setNquads);
164+
});
165+
166+
it("should get setNquads as b64", () => {
167+
const p = new dgraph.Mutation();
168+
p.setSetNquads(setNquads);
169+
170+
const b64 = p.getSetNquads_asB64();
171+
const nq = b64ToStr(b64);
172+
expect(nq).toEqual(setNquads);
173+
});
174+
175+
it("should get setNquads as u8", () => {
176+
const p = new dgraph.Mutation();
177+
p.setSetNquads(setNquads);
178+
179+
const u8 = p.getSetNquads_asU8();
180+
const nq = u8ToStr(u8);
181+
expect(nq).toEqual(setNquads);
182+
});
183+
184+
it("should set and get delNquads", () => {
185+
const p = new dgraph.Mutation();
186+
187+
p.setDelNquads(delNquads);
188+
let nq = p.getDelNquads();
189+
expect(nq).toEqual(delNquads);
190+
191+
p.setDelNquads(strToB64(delNquads));
192+
nq = p.getDelNquads();
193+
expect(nq).toEqual(delNquads);
194+
195+
p.setDelNquads(strToU8(delNquads));
196+
nq = p.getDelNquads();
197+
expect(nq).toEqual(delNquads);
198+
});
199+
200+
it("should get delNquads as b64", () => {
201+
const p = new dgraph.Mutation();
202+
p.setDelNquads(delNquads);
203+
204+
const b64 = p.getDelNquads_asB64();
205+
const nq = b64ToStr(b64);
206+
expect(nq).toEqual(delNquads);
207+
});
208+
209+
it("should get delNquads as u8", () => {
210+
const p = new dgraph.Mutation();
211+
p.setDelNquads(delNquads);
212+
213+
const u8 = p.getDelNquads_asU8();
214+
const nq = u8ToStr(u8);
215+
expect(nq).toEqual(delNquads);
216+
});
217+
});
218+
});

0 commit comments

Comments
 (0)