Add user mapping test
This commit is contained in:
parent
f81cf1e1fb
commit
ed2b206f18
5
jest.config.js
Normal file
5
jest.config.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
}
|
||||||
5382
package-lock.json
generated
5382
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -21,13 +21,14 @@
|
|||||||
"lint-fix": "eslint src/ --fix --ext .ts",
|
"lint-fix": "eslint src/ --fix --ext .ts",
|
||||||
"prefix": "npm run format-fix",
|
"prefix": "npm run format-fix",
|
||||||
"fix": "npm run lint-fix",
|
"fix": "npm run lint-fix",
|
||||||
"test": "echo \"Warning: no test specified\"",
|
"test": "jest",
|
||||||
"compile": "rm -rf dist/ && tsc",
|
"compile": "rm -rf dist/ && tsc",
|
||||||
"start": "npm run compile && node dist/app.js",
|
"start": "npm run compile && node dist/app.js",
|
||||||
"prepare": "husky install"
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jest": "^29.5.0",
|
||||||
"@types/n-readlines": "^1.0.3",
|
"@types/n-readlines": "^1.0.3",
|
||||||
"@types/node": "^20.2.1",
|
"@types/node": "^20.2.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.59.6",
|
"@typescript-eslint/eslint-plugin": "^5.59.6",
|
||||||
@ -42,6 +43,7 @@
|
|||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"lint-staged": "^13.2.2",
|
"lint-staged": "^13.2.2",
|
||||||
"prettier": "2.8.8",
|
"prettier": "2.8.8",
|
||||||
|
"ts-jest": "^29.1.0",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
21
src/users.test.ts
Normal file
21
src/users.test.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
process.env.REGISTRATION_SHARED_SECRET = 'ThisIsSoSecretWow'
|
||||||
|
import { RcUser, MatrixUser, mapUser } from './users'
|
||||||
|
|
||||||
|
const rcUser: RcUser = {
|
||||||
|
_id: 'testRc',
|
||||||
|
name: 'Tester',
|
||||||
|
username: 'test',
|
||||||
|
roles: ['user'],
|
||||||
|
__rooms: [],
|
||||||
|
}
|
||||||
|
const matrixUser: MatrixUser = {
|
||||||
|
user_id: '',
|
||||||
|
username: rcUser.username,
|
||||||
|
displayname: rcUser.name,
|
||||||
|
password: '',
|
||||||
|
admin: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
test('mapping users', () => {
|
||||||
|
expect(mapUser(rcUser)).toStrictEqual(matrixUser)
|
||||||
|
})
|
||||||
@ -3,10 +3,10 @@ import { axios } from './synapse'
|
|||||||
import { createHmac } from 'node:crypto'
|
import { createHmac } from 'node:crypto'
|
||||||
|
|
||||||
export type RcUser = {
|
export type RcUser = {
|
||||||
|
_id: string
|
||||||
username: string
|
username: string
|
||||||
name: string
|
name: string
|
||||||
roles: string[]
|
roles: string[]
|
||||||
_id: string
|
|
||||||
__rooms: string[]
|
__rooms: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user