-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TzeYiing
committed
Feb 12, 2021
1 parent
84a9e2b
commit bc6f78c
Showing
8 changed files
with
82 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import assert from "assert"; | ||
import Core from "../lib"; | ||
|
||
describe("features", function () { | ||
let core; | ||
it("a feature's schema is loaded", async function () { | ||
const cards = { | ||
schema: ` | ||
create table if not exists cards( | ||
id INTEGER PRIMARY KEY | ||
);`, | ||
}; | ||
core = await Core.init({ features: [cards] }, { internals: true }); | ||
|
||
const tables = core._internals.listTables; | ||
assert.ok(tables.includes("cards")); | ||
}); | ||
it("a feature's handlers can be declared", async function () { | ||
const cards = { | ||
schema: ` | ||
create table if not exists cards( | ||
id INTEGER PRIMARY KEY | ||
);`, | ||
handlers: { | ||
myHandler: (handlerArg) => { | ||
assert.ok(handlerArg); | ||
return "myHandler"; | ||
}, | ||
}, | ||
}; | ||
core = await Core.init({ features: { cards } }); | ||
const result = core.cards.myhandler(); | ||
assert.strictEqual(result, "myHandler"); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as assert from "assert"; | ||
import Core, { App } from "../lib"; | ||
|
||
describe("init", function () { | ||
let core: App; | ||
it("before initialization, no other keys are set", async function () { | ||
assert.ok("init" in Core); | ||
assert.rejects("state" in Core); | ||
core = await Core.init(); | ||
assert.ok("state" in core); | ||
assert.ok("init" in core); | ||
}); | ||
it("adds access to _internals when internals option is true", async function () { | ||
core = await Core.init({}, { internals: true }); | ||
assert.ok("_internals" in core); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import assert from "assert"; | ||
import Core from "../lib"; | ||
|
||
describe("state", function () { | ||
let core; | ||
it("core.state is empty object by default", async function () { | ||
core = await Core.init(); | ||
assert.strictEqual(core.state, {}); | ||
}); | ||
it("core.state returns declared state columns", async function () { | ||
core = await Core.init({ | ||
stateColumns: ["my_column integer"], | ||
}); | ||
assert.notStrictEqual(core.state, { my_column: null }); | ||
}); | ||
|
||
it("core.state calls buildState", async function () { | ||
let calls = 0; | ||
core = await Core.init({ | ||
buildState: (partial, core) => { | ||
calls++; | ||
assert.strictEqual(partial, {}); | ||
assert.ok(core); //gets a truthy value | ||
return { my_state: true }; | ||
}, | ||
}); | ||
assert.strictEqual(calls, 1); | ||
assert.strictEqual(core.state, { my_column: null }); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.