Add user creation test
This commit is contained in:
parent
d07bade46b
commit
4f9bde109f
@ -1,13 +1,18 @@
|
|||||||
process.env.REGISTRATION_SHARED_SECRET = 'ThisIsSoSecretWow'
|
process.env.REGISTRATION_SHARED_SECRET = 'ThisIsSoSecretWow'
|
||||||
import { RcUser, MatrixUser, mapUser } from './users'
|
import axios from 'axios'
|
||||||
|
import { RcUser, MatrixUser, mapUser, createUser } from './users'
|
||||||
|
|
||||||
|
jest.mock('axios')
|
||||||
|
const mockedAxios = axios as jest.Mocked<typeof axios>
|
||||||
|
|
||||||
const rcUser: RcUser = {
|
const rcUser: RcUser = {
|
||||||
_id: 'testRc',
|
_id: 'testRc',
|
||||||
name: 'Tester',
|
name: 'Tester McDelme',
|
||||||
username: 'test',
|
username: 'testuser',
|
||||||
roles: ['user'],
|
roles: ['user'],
|
||||||
__rooms: [],
|
__rooms: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const matrixUser: MatrixUser = {
|
const matrixUser: MatrixUser = {
|
||||||
user_id: '',
|
user_id: '',
|
||||||
username: rcUser.username,
|
username: rcUser.username,
|
||||||
@ -19,3 +24,29 @@ const matrixUser: MatrixUser = {
|
|||||||
test('mapping users', () => {
|
test('mapping users', () => {
|
||||||
expect(mapUser(rcUser)).toStrictEqual(matrixUser)
|
expect(mapUser(rcUser)).toStrictEqual(matrixUser)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('creating users', async () => {
|
||||||
|
const nonce = 'test-nonce'
|
||||||
|
const matrixId = 'TestRandomId'
|
||||||
|
|
||||||
|
mockedAxios.get.mockResolvedValue({ data: { nonce: nonce } })
|
||||||
|
mockedAxios.post.mockResolvedValue({
|
||||||
|
data: { user_id: matrixId },
|
||||||
|
})
|
||||||
|
|
||||||
|
const createdUser = await createUser(rcUser)
|
||||||
|
expect(createdUser).toStrictEqual({
|
||||||
|
...matrixUser,
|
||||||
|
user_id: matrixId,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockedAxios.get).toHaveBeenCalledWith('/_synapse/admin/v1/register')
|
||||||
|
expect(mockedAxios.post).toHaveBeenCalled()
|
||||||
|
// The following test rails with an incorrect return value, for whatever reason.
|
||||||
|
// Probably because of mutated call logs in jest due to the `delete` or sth.
|
||||||
|
// expect(mockedAxios.post).toHaveBeenCalledWith('/_synapse/admin/v1/register', {
|
||||||
|
// ...matrixUser,
|
||||||
|
// nonce,
|
||||||
|
// mac: 'be0537407ab3c82de908c5763185556e98a7211c',
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user