-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration.test.js
54 lines (52 loc) · 1.71 KB
/
integration.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
const { run } = require("./joplin-to-anki");
const joplin = require("./joplin-client");
const anki = require("./anki-client");
const testNote = require("./joplin-test-data/sample-note");
const dotenv = require("dotenv");
const assert = require("assert");
const { parsed: env } = dotenv.config();
const { newLogger, levelDebug } = require("./log");
const log = newLogger(levelDebug);
const jClient = joplin.newClient(env.JOPLIN_URL, env.JOPLIN_TOKEN, log);
const aClient = anki.newClient(env.ANKI_URL, log);
const fromDate = new Date().toISOString();
describe("Joplin to Anki integration", function () {
before("Healthcheck Joplin API", async function () {
await jClient.health();
});
before("Healthcheck Anki Connect API", async function () {
await aClient.health();
});
before("Create Joplin test note", async function () {
const note = await jClient.request(
jClient.urlGen("notes"),
"POST",
testNote
);
this.testNoteID = note.id;
});
after("Delete test note from Joplin", async function () {
await jClient.request(jClient.urlGen("notes", this.testNoteID), "DELETE");
});
after("Delete test note from Anki", async function () {
const notes = await aClient.findNote(
`tag:${aClient.formatTag(testNote.title)}`
);
await aClient.deleteNotes(notes);
});
before("run joplin-to-anki (import from Joplin to Anki)", async function () {
await run(
levelDebug,
env.JOPLIN_URL,
env.JOPLIN_TOKEN,
fromDate,
env.ANKI_URL
);
});
it("should create 3 Anki notes from Joplin note", async function () {
const notes = await aClient.findNote(
`tag:${aClient.formatTag(testNote.title)}`
);
assert.equal(notes.length, 3);
});
});