-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
85 lines (78 loc) · 2.06 KB
/
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
"use strict";
const fastify = require("fastify")();
const tap = require("tap");
const fastifyInfluxDB = require("./index");
tap.test("fastify influxDB is correctly injected", async test => {
test.plan(3);
fastify.register(fastifyInfluxDB, {
host: "localhost",
database: "NOAA_water_database",
schema: [
{
measurement: "average_temperature",
fields: {
"level description": "STRING",
water_level: "FLOAT"
},
tags: ["location"]
},
{
measurement: "h2o_pH",
fields: {
"level description": "STRING",
water_level: "FLOAT"
},
tags: ["location"]
},
{
measurement: "h2o_quality",
fields: {
"level description": "STRING",
water_level: "FLOAT"
},
tags: ["location"]
},
{
measurement: "h2o_temperature",
fields: {
"level description": "STRING",
water_level: "FLOAT"
},
tags: ["location"]
}
]
});
fastify.get("/", async (request, reply) => {
const { instance } = fastify.influxdb;
await instance.writePoints([
{
measurement: "h2o_temperature",
tags: { location: "athens" },
fields: { "level description": "Medium", water_level: 2.4324 }
}
]);
reply.send({
rows: await instance.query(`
select * from h2o_temperature
where location = ${fastify.influxdb.escape.stringLit(
"athens"
)}
order by time desc
limit 10
`)
});
});
try {
await fastify.ready();
const { payload } = await fastify.inject({
method: "GET",
url: "/"
});
const [fetchedRow] = JSON.parse(payload).rows;
test.strictEqual(fetchedRow["level description"], "Medium");
test.strictEqual(fetchedRow.location, "athens");
test.strictEqual(fetchedRow.water_level, 2.4324);
} catch (e) {
test.fail("Fastify threw", e);
}
});