forked from CenterForDigitalHumanities/rerum_server_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch.test.js
More file actions
39 lines (34 loc) · 1.56 KB
/
patch.test.js
File metadata and controls
39 lines (34 loc) · 1.56 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
import { jest } from "@jest/globals"
// Only real way to test an express route is to mount it and call it so that we can use the req, res, next.
import express from "express"
import request from "supertest"
import controller from '../../db-controller.js'
import config from '../../config/index.js'
// Here is the auth mock so we get a req.user and the controller can function without a NPE.
const addAuth = (req, res, next) => {
req.user = {"http://store.rerum.io/agent": "https://store.rerum.io/v1/id/agent007"}
next()
}
const routeTester = new express()
routeTester.use(express.json())
routeTester.use(express.urlencoded({ extended: false }))
// Mount our own /patch route without auth that will use controller.patch
routeTester.use("/patch", [addAuth, controller.patchUpdate])
const unique = new Date(Date.now()).toISOString().replace("Z", "")
it("'/patch' route functions", async () => {
const response = await request(routeTester)
.patch('/patch')
.send({"@id":`${config.RERUM_ID_PREFIX}11111`, "RERUM Update Test":unique})
.set("Content-Type", "application/json")
.then(resp => resp)
.catch(err => err)
expect(response.header.location).toBe(response.body["@id"])
expect(response.statusCode).toBe(200)
expect(response.body._id).toBeUndefined()
expect(response.headers["content-length"]).toBeTruthy()
expect(response.headers["content-type"]).toBeTruthy()
expect(response.headers["date"]).toBeTruthy()
expect(response.headers["etag"]).toBeTruthy()
expect(response.headers["allow"]).toBeTruthy()
expect(response.headers["link"]).toBeTruthy()
})