Spaces:
Paused
Paused
| import { readdirSync } from "fs"; | |
| import { HapticLinkServer } from "../../src/socket/hapticLinkServer" | |
| import { registerRoutes } from "../../src/socket/routes"; | |
| import { expect } from 'chai'; | |
| import { resolve } from "path"; | |
| describe("Router", () => { | |
| let server: HapticLinkServer = new HapticLinkServer(); | |
| beforeEach(() => { | |
| server = new HapticLinkServer(); | |
| }) | |
| it("should add routes", (done) => { | |
| registerRoutes(server); | |
| const files = readdirSync(resolve("src/socket/routes")); | |
| const routes: string[] = []; | |
| files.forEach(file => { | |
| if (file.startsWith("_")) return; | |
| routes.push(file.replace(".ts", "")); | |
| }); | |
| const registeredRoutes = Object.keys(server.routes); | |
| const missingRoutes: string[] = [] | |
| routes.forEach(route => { | |
| if (!registeredRoutes.includes(route)) { | |
| missingRoutes.push(route) | |
| } | |
| }) | |
| expect(missingRoutes.length).to.equal(0, "routes not registered: " + missingRoutes); | |
| done(); | |
| }) | |
| }) | |