-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmount.test.js
More file actions
141 lines (129 loc) · 4.65 KB
/
Copy pathmount.test.js
File metadata and controls
141 lines (129 loc) · 4.65 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Express Route Detection
*
* This approach checks routes without making HTTP requests by
* directly inspecting the Express app's routing table.
*/
import request from "supertest"
import { jest } from "@jest/globals"
import fs from "fs"
import app from "../../app.js"
beforeEach(() => {
// This comes from tokens.js in the app.js import. This apps tries to read env.ACCESS_TOKEN to refresh expired tokens.
// We don't care whether or not the token is expired here, so let's just state we don't care about tokens in tests.
updateExpiredToken = jest.fn(() => true)
isTokenExpired = jest.fn(() => false)
})
afterEach(() => {
/**
* Food for thought: delete data generated by tests?
* Make a test.store available that uses the same annotationStoreTesting as RERUM tests?
*/
})
/**
* Check if a route exists in the Express app
* Routes are checked by testing the matcher functions on each layer.
*
* @param {Array<string>} routes - Array of route paths to check
* @returns {boolean} - True if all routes are found
*/
function routeExists(routes) {
const foundRoutes = new Set()
const scanStack = (stack = []) => {
for (const layer of stack) {
if (layer.matchers && layer.matchers[0]) {
const matcher = layer.matchers[0]
for (const route of routes) {
if (matcher(route)) foundRoutes.add(route)
}
}
if (layer.regexp) {
for (const route of routes) {
if (layer.regexp.test(route)) foundRoutes.add(route)
}
}
if (layer.route && layer.route.path) {
for (const route of routes) {
if (layer.route.path === route) foundRoutes.add(route)
}
}
if (layer.handle?.stack) {
scanStack(layer.handle.stack)
}
}
}
scanStack(app._router?.stack)
// Check if all expected routes were found
return routes.every(route => foundRoutes.has(route))
}
/**
* This test suite uses the built app.js app and checks that the expected create endpoints are registered.
* - /create
* - /app/create
*/
describe("Check that the expected TinyNode create route patterns are registered.", () => {
it("'/app/create' and '/create' are registered routes in the app. __exists __core", () => {
const routes = ["/create", "/app/create"]
const exists = routeExists(routes)
expect(exists).toBe(true)
})
})
/**
* This test suite uses the built app.js app and checks that the expected query endpoints are registered.
* - /query
* - /app/query
*/
describe("Check that the expected TinyNode query route patterns are registered.", () => {
it("'/app/query' and '/query' are registered routes in the app. __exists __core", () => {
const routes = ["/query", "/app/query"]
const exists = routeExists(routes)
expect(exists).toBe(true)
})
})
/**
* This test suite uses the built app.js app and checks that the expected update endpoints are registered.
* - /update
* - /app/update
*/
describe("Check that the expected TinyNode update route patterns are registered.", () => {
it("'/app/update' and '/update' are registered routes in the app. __exists __core", () => {
const routes = ["/update", "/app/update"]
const exists = routeExists(routes)
expect(exists).toBe(true)
})
})
/**
* This test suite uses the built app.js app and checks that the expected overwrite endpoints are registered.
* - /overwrite
* - /app/overwrite
*/
describe("Check that the expected TinyNode overwrite route patterns are registered.", () => {
it("'/app/overwrite' and '/overwrite' are registered routes in the app. __exists __core", () => {
const routes = ["/overwrite", "/app/overwrite"]
const exists = routeExists(routes)
expect(exists).toBe(true)
})
})
/**
* This test suite uses the built app.js app and checks that the expected delete endpoints are registered.
* - /delete
* - /app/delete
*/
describe("Combined unit tests for the '/delete' route.", () => {
it("'/app/delete' and '/delete' are registered routes in the app. __exists __core", () => {
const routes = ["/delete", "/app/delete"]
const exists = routeExists(routes)
expect(exists).toBe(true)
})
})
describe('Check to see that critical repo files are present', () => {
it('root folder files', () => {
const filePath = './' // Replace with the actual file path
expect(fs.existsSync(filePath+"CODEOWNERS")).toBeTruthy()
expect(fs.existsSync(filePath+"CONTRIBUTING.md")).toBeTruthy()
expect(fs.existsSync(filePath+"README.md")).toBeTruthy()
expect(fs.existsSync(filePath+".gitignore")).toBeTruthy()
expect(fs.existsSync(filePath+"jest.config.js")).toBeTruthy()
expect(fs.existsSync(filePath+"package.json")).toBeTruthy()
})
})