Basic update test
This commit is contained in:
parent
4ddd450a89
commit
88e054c366
|
@ -32,6 +32,8 @@ describe("UserDB", () => {
|
||||||
db.init(quotas, groups, features)
|
db.init(quotas, groups, features)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("save", () => {
|
||||||
|
describe("create", () => {
|
||||||
it("creating a new user will persist it", async () => {
|
it("creating a new user will persist it", async () => {
|
||||||
const email = generator.email({})
|
const email = generator.email({})
|
||||||
const user: User = structures.users.user({
|
const user: User = structures.users.user({
|
||||||
|
@ -65,7 +67,9 @@ describe("UserDB", () => {
|
||||||
await config.doInTenant(() => db.save(user))
|
await config.doInTenant(() => db.save(user))
|
||||||
|
|
||||||
await config.doInTenant(() =>
|
await config.doInTenant(() =>
|
||||||
expect(db.save(user)).rejects.toThrow(`Email already in use: '${email}'`)
|
expect(db.save(user)).rejects.toThrow(
|
||||||
|
`Email already in use: '${email}'`
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -80,7 +84,45 @@ describe("UserDB", () => {
|
||||||
|
|
||||||
config.newTenant()
|
config.newTenant()
|
||||||
await config.doInTenant(() =>
|
await config.doInTenant(() =>
|
||||||
expect(db.save(user)).rejects.toThrow(`Email already in use: '${email}'`)
|
expect(db.save(user)).rejects.toThrow(
|
||||||
|
`Email already in use: '${email}'`
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("update", () => {
|
||||||
|
let user: User
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
user = await config.doInTenant(() =>
|
||||||
|
db.save(
|
||||||
|
structures.users.user({
|
||||||
|
email: generator.email({}),
|
||||||
|
tenantId: config.getTenantId(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("can update user properties", async () => {
|
||||||
|
await config.doInTenant(async () => {
|
||||||
|
const updatedName = generator.first()
|
||||||
|
user.firstName = updatedName
|
||||||
|
|
||||||
|
await db.save(user)
|
||||||
|
|
||||||
|
const persistedUser = await db.getUserByEmail(user.email)
|
||||||
|
expect(persistedUser).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
_id: user._id,
|
||||||
|
email: user.email,
|
||||||
|
firstName: updatedName,
|
||||||
|
lastName: user.lastName,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue