File size: 990 Bytes
a18eb38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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();
  })

})