65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { TestingModule, Test } from "@nestjs/testing"
|
|
import { SystemService } from "./system.service";
|
|
import { ActivityHelperService } from "src/shared/service/activity.logger.service";
|
|
import { ActivityHelperMockService } from "src/shared/service/activity.logger.service.mock";
|
|
import { MockUserRepository, MockKeySystemRepository, MockMailService } from "../../../mocks";
|
|
import { KeySystemRepository, UserRepository } from "src/model/repositories";
|
|
import { MailService } from "../mail/mail.service";
|
|
import { ConfigService } from "@nestjs/config";
|
|
import { KeySystem } from "src/model/entitites/system.entity";
|
|
import { User } from "src/model/entitites";
|
|
|
|
describe('KeySystemServce', () => {
|
|
let service: SystemService;
|
|
let user: User;
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [
|
|
SystemService,
|
|
{ provide: KeySystemRepository, useClass: MockKeySystemRepository },
|
|
{ provide: MailService, useClass: MockMailService },
|
|
{ provide: UserRepository, useClass: MockUserRepository },
|
|
{ provide: ActivityHelperService, useClass: ActivityHelperMockService },
|
|
ConfigService
|
|
],
|
|
imports: []
|
|
|
|
}).compile();
|
|
|
|
service = module.get<SystemService>(SystemService);
|
|
user = await service['userRepo'].findByUsername('mockuser@test.de', { settings: false })
|
|
});
|
|
|
|
|
|
it('should be defined', () => {
|
|
expect(service).toBeDefined();
|
|
});
|
|
|
|
it('should create a system', async () => {
|
|
const name = 'TestSystem0123'
|
|
const s = await service.create(user, { name });
|
|
expect(s).not.toBeNull();
|
|
expect(s.id).not.toBeNull();
|
|
expect(s.createdAt).not.toBeNull();
|
|
expect(s.name).toBe(name);
|
|
expect(s.managers).toContain(user);
|
|
expect(service['systemRepo'].create).toHaveBeenCalled()
|
|
expect(service['systemRepo'].save).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should delete systems', async () => {
|
|
const repo = service['systemRepo'];
|
|
const system = await service.remove('abc');
|
|
expect(repo.softRemove).toHaveBeenCalled();
|
|
expect(system.deletedAt).not.toBeNull();
|
|
})
|
|
|
|
it('should restore systems', async () => {
|
|
const repo = service['systemRepo'];
|
|
|
|
const system = await service.restore(user, 'abc');
|
|
expect(repo.save).toHaveBeenCalled();
|
|
expect(system.deletedAt).toBeNull();
|
|
})
|
|
}) |