-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsuiteql.test.js
102 lines (89 loc) · 3.08 KB
/
suiteql.test.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
99
100
101
102
const dotenv = require("dotenv").config();
const suiteql = require("./suiteql");
var suiteQL;
describe("Netsuite SuiteQL Tests", () => {
jest.setTimeout(10000);
test("it should check that secrets exists", () => {
expect(process.env.consumer_key).toBeDefined();
expect(process.env.consumer_secret_key).toBeDefined();
expect(process.env.token).toBeDefined();
expect(process.env.token_secret).toBeDefined();
expect(process.env.realm).toBeDefined();
expect(process.env.base_url).toBeDefined();
});
test("it should throw error if config is missing", () => {
const t = () => {
suiteQL = new suiteql()
};
expect(t).toThrow(TypeError);
});
test("it should not connect to NetSuite because of invalid token", () => {
expect.assertions(1);
suiteQL = new suiteql({
consumer_key: process.env.consumer_key,
consumer_secret_key: process.env.consumer_secret_key,
token: "INVALID TOKEN",
token_secret: process.env.token_secret,
realm: process.env.realm
});
return expect(suiteQL.connect()).rejects.toThrow(Error);
});
test("it should connect to NetSuite", () => {
expect.assertions(1);
suiteQL = new suiteql({
consumer_key: process.env.consumer_key,
consumer_secret_key: process.env.consumer_secret_key,
token: process.env.token,
token_secret: process.env.token_secret,
realm: process.env.realm,
base_url: process.env.base_url
});
return suiteQL.connect()
.then((response) => {
expect(response.statusCode).toEqual(204);
})
.catch((err) => {
console.log("Connect Test Failed.", err);
});
});
test("it should get 2 records from transaction table ", async () => {
expect.assertions(1);
let transactions = await suiteQL.query("select id from transaction", 2);
expect(transactions.items.length).toEqual(2);
});
test("it should get 0 records from transaction table ", async () => {
expect.assertions(1);
let transactions = await suiteQL.query(`select id from transaction where id = 1 `);
expect(transactions.items.length).toEqual(0);
});
test("it should throw error if query is not string", async () => {
expect.assertions(1);
await expect(
suiteQL.query(123)
).rejects.toThrow(Error);
});
test("it should throw error if query fails", async () => {
expect.assertions(1);
await expect(
suiteQL.query("select id from transactiontablethatdoesnotexist", 2)
).rejects.toThrow(Error);
});
test("it should throw error if limit exceeds 1000", async () => {
expect.assertions(1);
await expect(
suiteQL.query("select id from transaction", 1001)
).rejects.toThrow("Max limit is 1000");
});
test("it should get all 30 records from transaction table using queryAll", async (done) => {
expect.assertions(1);
let items = [];
let st = suiteQL.queryAll('select tranid, id from transaction where rownum <= 30');
st.on("data", (data) => {
items.push(data);
});
st.on("end", () => {
expect(items.length).toEqual(30);
done();
});
});
});