-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
52 lines (42 loc) · 1.13 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
const { suite } = require("uvu");
const assert = require("uvu/assert");
const sendLog = require("./lib/send-log");
const nock = require("nock");
nock.disableNetConnect();
const test = suite("app");
test("README example", async function () {
const metadata = { meta: "data" };
const inputs = {
api_key: "apikey123",
source_id: "sourceid123",
message: "my log message",
metadata: JSON.stringify(metadata),
};
const infoLogs = [];
const debugLogs = [];
const coreMock = {
getInput: (input) => inputs[input],
info: (what) => infoLogs.push(what),
debug: (what) => debugLogs.push(what),
};
nock("https://api.logflare.app")
.post("/logs?api_key=apikey123&source=sourceid123", {
log_entry: "my log message",
metadata,
})
.reply(200, '{"message":"Logged!"}');
await sendLog(coreMock).catch(console.log);
assert.equal(infoLogs, ["Log message sent."]);
assert.equal(debugLogs, [
"Sending log ...",
{
log_entry: "my log message",
metadata: {
meta: "data",
},
},
"Response from Logflare:",
'{"message":"Logged!"}',
]);
});
test.run();