mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 02:24:17 +00:00
update tests
This commit is contained in:
parent
f1d83f663d
commit
5ceb68a577
30
test/clientTest.js
Normal file
30
test/clientTest.js
Normal file
@ -0,0 +1,30 @@
|
||||
const assert = require("assert")
|
||||
const linebridgeClient = require("../dist/client/index.js")
|
||||
|
||||
const exampleTestHTTPPort = 3010
|
||||
|
||||
let exampleBridge = null
|
||||
|
||||
describe("[Client]", async function () {
|
||||
it("exports fine", function () {
|
||||
assert.equal(typeof linebridgeClient, "object")
|
||||
console.log(linebridgeClient)
|
||||
})
|
||||
|
||||
it("create test bridge", async () => {
|
||||
exampleBridge = new linebridgeClient.Bridge({
|
||||
origin: `http://0.0.0.0:${exampleTestHTTPPort}`,
|
||||
})
|
||||
|
||||
await exampleBridge.initialize()
|
||||
})
|
||||
|
||||
it("bridge.endpoints is an object", async () => {
|
||||
assert.equal(typeof exampleBridge.endpoints, "object")
|
||||
})
|
||||
|
||||
it("test endpoint should correctly respond", async () => {
|
||||
let response = await exampleBridge.endpoints.get.test()
|
||||
assert.equal(response.test, "testing")
|
||||
})
|
||||
})
|
@ -1,70 +0,0 @@
|
||||
const assert = require('assert')
|
||||
const linebridgeClient = require('../dist/client/index.js')
|
||||
const linebridgeServer = require('../dist/server/index.js')
|
||||
|
||||
const exampleTestHTTPPort = 3010
|
||||
|
||||
let exampleServer = null
|
||||
let exampleController = null
|
||||
let exampleBridge = null
|
||||
|
||||
describe('[Linebridge Server]', async function () {
|
||||
it('should export', function () {
|
||||
assert.equal(typeof linebridgeServer, 'function')
|
||||
})
|
||||
|
||||
it("initialize example server", async function () {
|
||||
exampleServer = new linebridgeServer({
|
||||
port: exampleTestHTTPPort,
|
||||
endpoints: [
|
||||
{
|
||||
route: '/test',
|
||||
method: 'GET',
|
||||
fn: function (req, res) {
|
||||
return res.send({test: 'testing'})
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
await exampleServer.init()
|
||||
})
|
||||
})
|
||||
|
||||
describe('[Linebridge Client]', async function () {
|
||||
it('exports should be lib objects and functions', function () {
|
||||
assert.equal(typeof linebridgeClient, 'object')
|
||||
})
|
||||
|
||||
it("create example controller", async function () {
|
||||
exampleController = new linebridgeClient.Controller({
|
||||
servers: [
|
||||
`http://localhost:${exampleTestHTTPPort}`
|
||||
]
|
||||
})
|
||||
|
||||
await exampleController.initialize()
|
||||
|
||||
console.log(exampleController)
|
||||
})
|
||||
|
||||
it("create example bridge", async () => {
|
||||
exampleBridge = new linebridgeClient.Bridge({
|
||||
origin: `http://localhost:${exampleTestHTTPPort}`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
await exampleBridge.initialize()
|
||||
})
|
||||
|
||||
it("bridge.endpoints is an object", async () => {
|
||||
assert.equal(typeof exampleBridge.endpoints, 'object')
|
||||
})
|
||||
|
||||
it("test endpoint should correctly respond", async () => {
|
||||
let response = await exampleBridge.endpoints.get.test()
|
||||
assert.equal(response.test, 'testing')
|
||||
})
|
||||
})
|
60
test/serverTest.js
Normal file
60
test/serverTest.js
Normal file
@ -0,0 +1,60 @@
|
||||
const assert = require("assert")
|
||||
const linebridgeServer = require("../dist/server/index.js")
|
||||
|
||||
const exampleTestHTTPPort = 3010
|
||||
|
||||
const testEndpoints = [
|
||||
{
|
||||
route: "/test",
|
||||
method: "GET",
|
||||
fn: function (req, res) {
|
||||
return res.send({ test: "testing" })
|
||||
}
|
||||
},
|
||||
{
|
||||
route: "/disabledByDefault",
|
||||
method: "GET",
|
||||
fn: function (req, res) {
|
||||
return res.send("This must not be sended")
|
||||
},
|
||||
enabled: false,
|
||||
},
|
||||
{
|
||||
route: "/shouldBeDisabled",
|
||||
method: "GET",
|
||||
fn: function (req, res) {
|
||||
return res.send("This must not be sended after use `toogleEndpointReachability`")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
let exampleServer = null
|
||||
|
||||
describe("[Server]", async function () {
|
||||
it("should export", function () {
|
||||
assert.equal(typeof linebridgeServer, "function")
|
||||
})
|
||||
|
||||
it("create server", async function () {
|
||||
exampleServer = new linebridgeServer({
|
||||
port: exampleTestHTTPPort,
|
||||
})
|
||||
})
|
||||
|
||||
it("register test controllers", async function () {
|
||||
testEndpoints.forEach((endpoint) => {
|
||||
exampleServer.registerHTTPEndpoint(endpoint)
|
||||
})
|
||||
})
|
||||
|
||||
it("initialize server", async function () {
|
||||
await exampleServer.initialize()
|
||||
})
|
||||
|
||||
it("toogleEndpointReachability", async function () {
|
||||
exampleServer.toogleEndpointReachability("get", "/shouldBeDisabled", false)
|
||||
|
||||
// check if endpoint is disabled
|
||||
assert.equal(exampleServer.endpointsMap["get"]["/shouldBeDisabled"].enabled, false)
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user