@jfln/marvin-db
Version:
biblioteca de objetos para normalizar o acesso a um banco mongo db
72 lines (59 loc) • 1.81 kB
text/typescript
import 'reflect-metadata'
import {EntityManager, MikroORM} from '@mikro-orm/core'
import {Audit} from '..'
import {AuditType} from '../../types/Audit.types'
import {User} from 'interfaces/User.interface'
import {Content} from 'interfaces/Content.interface'
import options from '../../mikro-orm.config'
describe('Audits Entity', () => {
let ormAudit: MikroORM
let em: EntityManager
let content: Content
let user: User
beforeAll(async () => {
ormAudit = await MikroORM.init(options)
em = ormAudit.em.fork()
content = {
message: 'Apenas um simples teste',
messageId: '123456789',
number: '1',
}
user = {id: '9876543210', name: 'Teste'}
})
afterAll(() => {
ormAudit.close(true)
})
it('should be able to create an Audit', async () => {
const audit = new Audit(
AuditType.AUTO_MODERATION,
false,
'123456789',
content,
user,
)
await em.persistAndFlush(audit)
expect(audit._id).toBeDefined()
})
it('should be able to find an Audit', async () => {
const audit = await em.findOne(Audit, {guildId: '123456789'})
expect(audit).toBeDefined()
})
it('should be able to update an Answer', async () => {
const audit = await em.findOne(Audit, {guildId: '123456789'})
expect(audit).toBeDefined()
if (audit) {
audit.auditType = AuditType.CONFESSION
await em.persistAndFlush(audit)
expect(audit.auditType).toEqual(AuditType.CONFESSION)
}
})
it('should be able to delete an Audit', async () => {
const audit = await em.findOne(Audit, {guildId: '123456789'})
expect(audit).toBeDefined()
if (audit) {
await em.removeAndFlush(audit)
const audit2 = await em.findOne(Audit, {guildId: '123456789'})
expect(audit2).toBeNull()
}
})
})