Add user mapping test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Henrik HerHde Huettemann 2023-05-26 17:42:03 +02:00
parent f81cf1e1fb
commit ed2b206f18
Signed by: HueHe
GPG key ID: 9F7BD10E0A8A111E
5 changed files with 5410 additions and 4 deletions

5
jest.config.js Normal file
View file

@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}

5382
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -21,13 +21,14 @@
"lint-fix": "eslint src/ --fix --ext .ts",
"prefix": "npm run format-fix",
"fix": "npm run lint-fix",
"test": "echo \"Warning: no test specified\"",
"test": "jest",
"compile": "rm -rf dist/ && tsc",
"start": "npm run compile && node dist/app.js",
"prepare": "husky install"
},
"version": "0.1.0",
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/n-readlines": "^1.0.3",
"@types/node": "^20.2.1",
"@typescript-eslint/eslint-plugin": "^5.59.6",
@ -42,6 +43,7 @@
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "2.8.8",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
},
"dependencies": {

21
src/users.test.ts Normal file
View 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)
})

View file

@ -3,10 +3,10 @@ import { axios } from './synapse'
import { createHmac } from 'node:crypto'
export type RcUser = {
_id: string
username: string
name: string
roles: string[]
_id: string
__rooms: string[]
}