add new tests

This commit is contained in:
admin 2025-08-24 14:37:14 +02:00
parent acdbc9d402
commit 1d9f3e8d5f
20 changed files with 448 additions and 213 deletions

12
package-lock.json generated
View File

@ -1,15 +1,15 @@
{ {
"name": "@apihub24/token-authentication", "name": "@apihub24/token-authentication",
"version": "1.0.5", "version": "1.0.6",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@apihub24/token-authentication", "name": "@apihub24/token-authentication",
"version": "1.0.5", "version": "1.0.6",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@apihub24/authentication": "^1.0.1", "@apihub24/authentication": "2.0.0-alpha.0",
"@apihub24/repository": "^1.0.3", "@apihub24/repository": "^1.0.3",
"@apihub24/translation": "^1.0.1", "@apihub24/translation": "^1.0.1",
"@nestjs/common": "^11.1.6", "@nestjs/common": "^11.1.6",
@ -42,9 +42,9 @@
} }
}, },
"node_modules/@apihub24/authentication": { "node_modules/@apihub24/authentication": {
"version": "1.0.1", "version": "2.0.0-alpha.0",
"resolved": "https://registry.npmjs.org/@apihub24/authentication/-/authentication-1.0.1.tgz", "resolved": "https://registry.npmjs.org/@apihub24/authentication/-/authentication-2.0.0-alpha.0.tgz",
"integrity": "sha512-nWw75ofQKHxE0dI7PzvNBQNcQrX/HSrzuAJTYNu42BoCROba1NUz8QAodTn5+3dIeQEzw127gtSb6D7yW0B8Jg==", "integrity": "sha512-e7ZGD2fHSo2LJFuu9/6lJ4JMq52anK1jUe5btusVbNRzAP+8lrFcwytlctLUF2Adtlg/DgLGrLzCgSm+g19TVw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@apihub24/repository": { "node_modules/@apihub24/repository": {

View File

@ -1,12 +1,13 @@
{ {
"name": "@apihub24/token-authentication", "name": "@apihub24/token-authentication",
"version": "1.0.5", "version": "2.0.0-alpha.0",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"scripts": { "scripts": {
"build": "rimraf ./dist && tsc", "build": "rimraf ./dist && tsc",
"test": "jest", "test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage", "test:coverage": "jest --coverage",
"pub": "npm publish", "pub": "npm publish",
"rel": "npm i && npm run build && npm run test:coverage" "rel": "npm i && npm run build && npm run test:coverage"
@ -15,7 +16,7 @@
"@nestjs/common": "^11.1.6", "@nestjs/common": "^11.1.6",
"@nestjs/config": "^4.0.2", "@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.1.6", "@nestjs/core": "^11.1.6",
"@apihub24/authentication": "^1.0.1", "@apihub24/authentication": "2.0.0-alpha.0",
"@apihub24/repository": "^1.0.3", "@apihub24/repository": "^1.0.3",
"@apihub24/translation": "^1.0.1", "@apihub24/translation": "^1.0.1",
"class-validator": "^0.14.2", "class-validator": "^0.14.2",

View File

@ -23,7 +23,7 @@ export class TokenGuard implements CanActivate {
*/ */
constructor( constructor(
private reflector: Reflector, private reflector: Reflector,
@Inject("@apihub24/token_service") @Inject(authentication.APIHUB24_TOKEN_SERVICE)
private readonly tokenService: authentication.ITokenService private readonly tokenService: authentication.ITokenService
) {} ) {}

View File

@ -6,6 +6,7 @@ import {
} from "../"; } from "../";
import { import {
APIHUB24_PASSWORD_SERVICE, APIHUB24_PASSWORD_SERVICE,
IPasswordService,
IRegistration, IRegistration,
} from "@apihub24/authentication"; } from "@apihub24/authentication";
import { MailServiceMockModule } from "../../test/mail.verification.service.mock"; import { MailServiceMockModule } from "../../test/mail.verification.service.mock";
@ -18,11 +19,51 @@ import { RightRepositoryMockModule } from "../../test/right.repository.mock";
import { OrganizationRepositoryMockModule } from "../../test/organization.repository.mock"; import { OrganizationRepositoryMockModule } from "../../test/organization.repository.mock";
import { Group } from "../models/group"; import { Group } from "../models/group";
import { Organization } from "../models/organization"; import { Organization } from "../models/organization";
import * as validator from "class-validator";
import * as transformer from "class-transformer";
import { Account } from "../models/account";
import { Registration } from "../models/registration";
describe("AccountFactoryService Tests", () => { describe("AccountFactoryService Tests", () => {
let module: TestingModule | null = null; let service: AccountFactoryService;
let passwordService: IPasswordService;
let groupService: GroupService;
let module: TestingModule;
const mockedPasswordHash = "hashed_password_123";
const mockedAdminGroup = {
id: "1",
name: "admin",
organization: {
id: "1",
name: "root",
} as Organization,
rights: [],
} as Group;
const mockedRegistration: IRegistration = {
accountName: "test",
email: "test@example.de",
password: "123",
passwordComparer: "123",
groupIds: [mockedAdminGroup.id],
};
jest.spyOn(transformer, "plainToClass").mockImplementation((cls, obj) => {
if (cls.name === "Account") {
const account = new Account();
Object.assign(account, obj);
return account;
}
if (cls.name === "Registration") {
const registration = new Registration();
Object.assign(registration, obj);
return registration;
}
return obj;
});
beforeAll(async () => { beforeAll(async () => {
// create testing module
module = await Test.createTestingModule({ module = await Test.createTestingModule({
imports: [ imports: [
MailServiceMockModule.forRoot(), MailServiceMockModule.forRoot(),
@ -35,42 +76,72 @@ describe("AccountFactoryService Tests", () => {
OrganizationRepositoryMockModule.forRoot(), OrganizationRepositoryMockModule.forRoot(),
TokenAuthenticationModule.forRoot(), TokenAuthenticationModule.forRoot(),
], ],
}).compile(); })
.overrideProvider(APIHUB24_PASSWORD_SERVICE)
.useValue({
hash: jest.fn().mockResolvedValue(mockedPasswordHash),
})
.overrideProvider(GroupService)
.useValue({
getBy: jest.fn().mockResolvedValue([]),
})
.compile();
// get services
service = module.get<AccountFactoryService>(AccountFactoryService);
passwordService = module.get<IPasswordService>(APIHUB24_PASSWORD_SERVICE);
groupService = module.get<GroupService>(GroupService);
jest.clearAllMocks();
}); });
it("should create Account from Registration", async () => { it("should be defined", () => {
expect(module).toBeDefined(); expect(module).toBeDefined();
const service = module?.get(AccountFactoryService);
const groupService = module?.get(GroupService);
const passwordService = module?.get(APIHUB24_PASSWORD_SERVICE);
expect(service).toBeDefined(); expect(service).toBeDefined();
expect(groupService).toBeDefined();
expect(passwordService).toBeDefined(); expect(passwordService).toBeDefined();
expect(groupService).toBeDefined();
});
const adminGroup = new Group(); it("should create inactive Account from Registration with unverified Email", async () => {
adminGroup.id = "1"; const user = await service.createFromRegistration(mockedRegistration);
adminGroup.name = "admin";
adminGroup.organization = new Organization();
adminGroup.organization.id = "1";
adminGroup.organization.name = "root";
adminGroup.rights = [];
const registration: IRegistration = {
accountName: "test",
email: "test@example.de",
password: "123",
passwordComparer: "123",
groupIds: ["1"],
};
jest
.spyOn(groupService!, "getBy")
.mockReturnValue(Promise.resolve([adminGroup]));
jest.spyOn(passwordService, "hash").mockReturnValue(registration.password);
const user = await service?.createFromRegistration(registration);
expect(user).toBeDefined(); expect(user).toBeDefined();
expect(user?.accountName).toBe(registration.accountName); expect(user.accountName).toBe(mockedRegistration.accountName);
expect(user?.email).toBe(registration.email); expect(user.email).toBe(mockedRegistration.email);
expect(user?.passwordHash).toBe(registration.password); expect(user.passwordHash).toBe(mockedPasswordHash);
expect(user?.emailVerified).toBeFalsy(); expect(user.emailVerified).toBeFalsy();
expect(user?.active).toBeFalsy(); expect(user.active).toBeFalsy();
});
it("should throw Error on invalid Registration", async () => {
const errorMessage = "Invalid Registration data";
jest.spyOn(validator, "validate").mockReturnValueOnce(
Promise.resolve([
{
toString: () => errorMessage,
} as validator.ValidationError,
])
);
expect(service.createFromRegistration(mockedRegistration)).rejects.toThrow(
errorMessage
);
});
it("should throw Error on invalid Account", async () => {
const errorMessage = "Invalid Account data";
jest
.spyOn(validator, "validate")
.mockReturnValueOnce(Promise.resolve([]))
.mockReturnValueOnce(
Promise.resolve([
{
toString: () => errorMessage,
} as validator.ValidationError,
])
);
expect(service.createFromRegistration(mockedRegistration)).rejects.toThrow(
errorMessage
);
}); });
}); });

View File

@ -0,0 +1,230 @@
import { Test, TestingModule } from "@nestjs/testing";
import { AccountService, TokenAuthenticationModule } from "../";
import { MailServiceMockModule } from "../../test/mail.verification.service.mock";
import { PasswordServiceMockModule } from "../../test/password.service.mock";
import { SessionServiceMockModule } from "../../test/session.service.mock";
import { TokenServiceMockModule } from "../../test/token.service.mock";
import { AccountRepositoryMockModule } from "../../test/account.repository.mock";
import { GroupRepositoryMockModule } from "../../test/group.repository.mock";
import { RightRepositoryMockModule } from "../../test/right.repository.mock";
import { OrganizationRepositoryMockModule } from "../../test/organization.repository.mock";
import { IRepository } from "@apihub24/repository";
import {
APIHUB24_ACCOUNT_REPOSITORY,
APIHUB24_GROUP_REPOSITORY,
IAccount,
IGroup,
} from "@apihub24/authentication";
describe("AccountService Tests", () => {
let module: TestingModule;
let service: AccountService;
let accountRepository: IRepository<IAccount>;
let groupRepository: IRepository<IGroup>;
const mockedAdminGroup: IGroup = {
id: "1",
name: "admin",
organization: {
id: "1",
name: "root",
},
rights: [],
};
const mockedAdminAccount: IAccount = {
id: "1",
accountName: "admin",
email: "admin@example.de",
passwordHash: "123",
active: true,
emailVerified: true,
groups: [mockedAdminGroup],
};
beforeAll(async () => {
module = await Test.createTestingModule({
imports: [
MailServiceMockModule.forRoot(),
PasswordServiceMockModule.forRoot(),
SessionServiceMockModule.forRoot(),
TokenServiceMockModule.forRoot(),
AccountRepositoryMockModule.forRoot(),
GroupRepositoryMockModule.forRoot(),
RightRepositoryMockModule.forRoot(),
OrganizationRepositoryMockModule.forRoot(),
TokenAuthenticationModule.forRoot(),
],
}).compile();
service = module.get(AccountService);
accountRepository = module.get(APIHUB24_ACCOUNT_REPOSITORY);
groupRepository = module.get(APIHUB24_GROUP_REPOSITORY);
jest.clearAllMocks();
});
it("should be defined", () => {
expect(service).toBeDefined();
expect(accountRepository).toBeDefined();
expect(groupRepository).toBeDefined();
});
describe("getBy", () => {
it("should get accounts by filter", async () => {
jest
.spyOn(accountRepository, "getBy")
.mockResolvedValueOnce([mockedAdminAccount]);
const filter = (x) => x.accountName === "admin";
const result = await service.getBy(filter);
expect(result).toStrictEqual([mockedAdminAccount]);
expect(accountRepository.getBy).toHaveBeenCalledWith(filter);
});
});
describe("save", () => {
it("should save accounts", async () => {
jest
.spyOn(accountRepository, "save")
.mockReturnValueOnce(Promise.resolve([mockedAdminAccount]));
const result = await service.save(mockedAdminAccount);
expect(result).toBe(mockedAdminAccount);
expect(accountRepository.save).toHaveBeenCalledWith([mockedAdminAccount]);
});
it("should return null when save fails", async () => {
jest
.spyOn(accountRepository, "save")
.mockReturnValueOnce(Promise.resolve([]));
const result = await service.save(mockedAdminAccount);
expect(result).toBeNull();
});
it("should return null when save throws an Error", async () => {
const errorMessage = "some Repository Error";
jest
.spyOn(accountRepository, "save")
.mockRejectedValueOnce(new Error(errorMessage));
const result = await service.save(mockedAdminAccount);
expect(result).toBeNull();
});
});
describe("delete", () => {
it("should delete Accounts", async () => {
const filter = (x) => x.accountName === "admin";
jest
.spyOn(accountRepository, "deleteBy")
.mockReturnValueOnce(Promise.resolve(true));
const result = await service.delete(filter);
expect(result).toBeTruthy();
expect(accountRepository.deleteBy).toHaveBeenLastCalledWith(filter);
});
});
describe("addAccountToGroup", () => {
it("should add a Account to a Group", async () => {
jest
.spyOn(accountRepository, "getBy")
.mockReturnValueOnce(
Promise.resolve([{ ...mockedAdminAccount, groups: [] }])
);
jest
.spyOn(groupRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([mockedAdminGroup]));
jest
.spyOn(accountRepository, "save")
.mockReturnValue(
Promise.resolve([
{ ...mockedAdminAccount, groups: [mockedAdminGroup] },
])
);
const result = await service.addAccountToGroup(
mockedAdminAccount.id,
mockedAdminGroup.id
);
expect(result.groups).toContainEqual(mockedAdminGroup);
expect(accountRepository.getBy).toHaveBeenCalledWith(
expect.any(Function)
);
expect(groupRepository.getBy).toHaveBeenCalledWith(expect.any(Function));
expect(accountRepository.save).toHaveBeenCalled();
});
it("should throw Error when Account not found", async () => {
jest
.spyOn(accountRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([]));
expect(
service.addAccountToGroup(mockedAdminAccount.id, mockedAdminGroup.id)
).rejects.toThrow(new Error("account with id 1 not found"));
});
it("should throw Error when Group not found", async () => {
jest
.spyOn(accountRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([mockedAdminAccount]));
jest
.spyOn(groupRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([]));
expect(
service.addAccountToGroup(mockedAdminAccount.id, mockedAdminGroup.id)
).rejects.toThrow(new Error("group with id 1 not found"));
});
});
describe("removeAccountFromGroup", () => {
it("should remove Account from Group", async () => {
jest
.spyOn(accountRepository, "getBy")
.mockReturnValueOnce(
Promise.resolve([
{ ...mockedAdminAccount, groups: [mockedAdminGroup] },
])
);
jest
.spyOn(groupRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([mockedAdminGroup]));
jest
.spyOn(accountRepository, "save")
.mockReturnValue(
Promise.resolve([{ ...mockedAdminAccount, groups: [] }])
);
const result = await service.removeAccountFromGroup(
mockedAdminAccount.id,
mockedAdminGroup.id
);
expect(result.groups).not.toContainEqual(mockedAdminGroup);
expect(accountRepository.getBy).toHaveBeenCalledWith(
expect.any(Function)
);
expect(groupRepository.getBy).toHaveBeenCalledWith(expect.any(Function));
expect(accountRepository.save).toHaveBeenCalled();
});
it("should throw Error when Account not found", async () => {
jest
.spyOn(accountRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([]));
expect(
service.removeAccountFromGroup(
mockedAdminAccount.id,
mockedAdminGroup.id
)
).rejects.toThrow(new Error("account with id 1 not found"));
});
it("should throw Error when Group not found", async () => {
jest
.spyOn(accountRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([mockedAdminAccount]));
jest
.spyOn(groupRepository, "getBy")
.mockReturnValueOnce(Promise.resolve([]));
expect(
service.removeAccountFromGroup(
mockedAdminAccount.id,
mockedAdminGroup.id
)
).rejects.toThrow(new Error("group with id 1 not found"));
});
});
});

View File

@ -1,13 +1,18 @@
import { IAccount, IGroup } from "@apihub24/authentication"; import {
APIHUB24_ACCOUNT_REPOSITORY,
APIHUB24_GROUP_REPOSITORY,
IAccount,
IGroup,
} from "@apihub24/authentication";
import * as repository from "@apihub24/repository"; import * as repository from "@apihub24/repository";
import { Inject, Injectable } from "@nestjs/common"; import { Inject, Injectable } from "@nestjs/common";
@Injectable() @Injectable()
export class AccountService { export class AccountService {
constructor( constructor(
@Inject("@apihub24/account_repository") @Inject(APIHUB24_ACCOUNT_REPOSITORY)
private readonly accountRepository: repository.IRepository<IAccount>, private readonly accountRepository: repository.IRepository<IAccount>,
@Inject("@apihub24/group_repository") @Inject(APIHUB24_GROUP_REPOSITORY)
private readonly groupRepository: repository.IRepository<IGroup> private readonly groupRepository: repository.IRepository<IGroup>
) {} ) {}

View File

@ -1,13 +1,18 @@
import { Inject, Injectable } from "@nestjs/common"; import { Inject, Injectable } from "@nestjs/common";
import * as repository from "@apihub24/repository"; import * as repository from "@apihub24/repository";
import { IGroup, IRight } from "@apihub24/authentication"; import {
APIHUB24_GROUP_REPOSITORY,
APIHUB24_RIGHT_REPOSITORY,
IGroup,
IRight,
} from "@apihub24/authentication";
@Injectable() @Injectable()
export class GroupService { export class GroupService {
constructor( constructor(
@Inject("@apihub24/group_repository") @Inject(APIHUB24_GROUP_REPOSITORY)
private readonly groupRepository: repository.IRepository<IGroup>, private readonly groupRepository: repository.IRepository<IGroup>,
@Inject("@apihub24/right_repository") @Inject(APIHUB24_RIGHT_REPOSITORY)
private readonly rightRepository: repository.IRepository<IRight> private readonly rightRepository: repository.IRepository<IRight>
) {} ) {}

View File

@ -5,11 +5,11 @@ import * as authentication from "@apihub24/authentication";
@Injectable() @Injectable()
export class LoginService { export class LoginService {
constructor( constructor(
@Inject("@apihub24/token_service") @Inject(authentication.APIHUB24_TOKEN_SERVICE)
private readonly tokenService: authentication.ITokenService, private readonly tokenService: authentication.ITokenService,
@Inject("@apihub24/password_service") @Inject(authentication.APIHUB24_PASSWORD_SERVICE)
private readonly passwordService: authentication.IPasswordService, private readonly passwordService: authentication.IPasswordService,
@Inject("@apihub24/session_service") @Inject(authentication.APIHUB24_SESSION_SERVICE)
private readonly sessionService: authentication.ISessionService, private readonly sessionService: authentication.ISessionService,
@Inject(AccountService) @Inject(AccountService)
private readonly accountService: AccountService private readonly accountService: AccountService

View File

@ -1,11 +1,14 @@
import { Inject, Injectable } from "@nestjs/common"; import { Inject, Injectable } from "@nestjs/common";
import * as repository from "@apihub24/repository"; import * as repository from "@apihub24/repository";
import { IOrganization } from "@apihub24/authentication"; import {
APIHUB24_ORGANIZATION_REPOSITORY,
IOrganization,
} from "@apihub24/authentication";
@Injectable() @Injectable()
export class OrganizationService { export class OrganizationService {
constructor( constructor(
@Inject("@apihub24/organization_repository") @Inject(APIHUB24_ORGANIZATION_REPOSITORY)
private readonly organizationRepository: repository.IRepository<IOrganization> private readonly organizationRepository: repository.IRepository<IOrganization>
) {} ) {}

View File

@ -10,7 +10,7 @@ export class RegistrationService {
private readonly accountService: AccountService, private readonly accountService: AccountService,
@Inject(AccountFactoryService) @Inject(AccountFactoryService)
private readonly accountFactory: AccountFactoryService, private readonly accountFactory: AccountFactoryService,
@Inject("@apihub24/mail_verification_service") @Inject(authentication.APIHUB24_MAIL_SERVICE)
private readonly mailVerificationService: authentication.IMailVerificationService private readonly mailVerificationService: authentication.IMailVerificationService
) {} ) {}

View File

@ -1,11 +1,11 @@
import { Inject, Injectable } from "@nestjs/common"; import { Inject, Injectable } from "@nestjs/common";
import * as repository from "@apihub24/repository"; import * as repository from "@apihub24/repository";
import { IRight } from "@apihub24/authentication"; import { APIHUB24_RIGHT_REPOSITORY, IRight } from "@apihub24/authentication";
@Injectable() @Injectable()
export class RightService { export class RightService {
constructor( constructor(
@Inject("@apihub24/right_repository") @Inject(APIHUB24_RIGHT_REPOSITORY)
private readonly rightRepository: repository.IRepository<IRight> private readonly rightRepository: repository.IRepository<IRight>
) {} ) {}

View File

@ -65,44 +65,4 @@ describe("TokenAuthenticationModule Tests", () => {
expect(module).toBeDefined(); expect(module).toBeDefined();
expect(module?.get(AccountFactoryService)).toBeDefined(); expect(module?.get(AccountFactoryService)).toBeDefined();
}); });
it("should provide @apihub24/mail_verification_service implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/mail_verification_service")).toBeDefined();
});
it("should provide @apihub24/token_service implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/token_service")).toBeDefined();
});
it("should provide @apihub24/session_service implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/session_service")).toBeDefined();
});
it("should provide @apihub24/password_service implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/password_service")).toBeDefined();
});
it("should provide @apihub24/account_repository implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/account_repository")).toBeDefined();
});
it("should provide @apihub24/group_repository implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/group_repository")).toBeDefined();
});
it("should provide @apihub24/right_repository implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/right_repository")).toBeDefined();
});
it("should provide @apihub24/organization_repository implementation", () => {
expect(module).toBeDefined();
expect(module?.get("@apihub24/organization_repository")).toBeDefined();
});
}); });

View File

@ -1,6 +1,9 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { IAccount } from "../src";
import { IRepository } from "@apihub24/repository"; import { IRepository } from "@apihub24/repository";
import {
APIHUB24_ACCOUNT_REPOSITORY,
IAccount,
} from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
@ -8,8 +11,12 @@ export class AccountRepositoryMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ {
provide: "@apihub24/account_repository", provide: APIHUB24_ACCOUNT_REPOSITORY,
useClass: AccountRepositoryMock, useValue: {
deleteBy: jest.fn(),
getBy: jest.fn(),
save: jest.fn(),
} as IRepository<IAccount>,
}, },
]; ];
return { return {
@ -19,15 +26,3 @@ export class AccountRepositoryMockModule {
}; };
} }
} }
class AccountRepositoryMock implements IRepository<IAccount> {
getBy(filter: (model: IAccount) => boolean): Promise<IAccount[]> {
throw new Error("Method not implemented.");
}
save(models: IAccount[]): Promise<IAccount[]> {
throw new Error("Method not implemented.");
}
deleteBy(filter: (model: IAccount) => boolean): Promise<boolean> {
throw new Error("Method not implemented.");
}
}

View File

@ -1,6 +1,6 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { IGroup } from "../src";
import { IRepository } from "@apihub24/repository"; import { IRepository } from "@apihub24/repository";
import { APIHUB24_GROUP_REPOSITORY, IGroup } from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
@ -8,8 +8,12 @@ export class GroupRepositoryMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ {
provide: "@apihub24/group_repository", provide: APIHUB24_GROUP_REPOSITORY,
useClass: GroupRepositoryMock, useValue: {
deleteBy: jest.fn(),
getBy: jest.fn(),
save: jest.fn(),
} as IRepository<IGroup>,
}, },
]; ];
return { return {
@ -19,15 +23,3 @@ export class GroupRepositoryMockModule {
}; };
} }
} }
class GroupRepositoryMock implements IRepository<IGroup> {
getBy(filter: (model: IGroup) => boolean): Promise<IGroup[]> {
throw new Error("Method not implemented.");
}
save(models: IGroup[]): Promise<IGroup[]> {
throw new Error("Method not implemented.");
}
deleteBy(filter: (model: IGroup) => boolean): Promise<boolean> {
throw new Error("Method not implemented.");
}
}

View File

@ -1,5 +1,8 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { IAccount, ISession, IMailVerificationService } from "../src"; import {
APIHUB24_MAIL_SERVICE,
IMailVerificationService,
} from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
@ -7,8 +10,11 @@ export class MailServiceMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ {
provide: "@apihub24/mail_verification_service", provide: APIHUB24_MAIL_SERVICE,
useClass: MailServiceMock, useValue: {
sendVerificationMail: jest.fn(),
verify: jest.fn(),
} as IMailVerificationService,
}, },
]; ];
return { return {
@ -18,12 +24,3 @@ export class MailServiceMockModule {
}; };
} }
} }
class MailServiceMock implements IMailVerificationService {
sendVerificationMail(account: IAccount): Promise<void> {
throw new Error("Method not implemented.");
}
verify(email: string, code: string): Promise<boolean> {
throw new Error("Method not implemented.");
}
}

View File

@ -1,6 +1,9 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { IOrganization } from "../src";
import { IRepository } from "@apihub24/repository"; import { IRepository } from "@apihub24/repository";
import {
APIHUB24_ORGANIZATION_REPOSITORY,
IOrganization,
} from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
@ -8,8 +11,12 @@ export class OrganizationRepositoryMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ {
provide: "@apihub24/organization_repository", provide: APIHUB24_ORGANIZATION_REPOSITORY,
useClass: OrganizationRepositoryMock, useValue: {
deleteBy: jest.fn(),
getBy: jest.fn(),
save: jest.fn(),
} as IRepository<IOrganization>,
}, },
]; ];
return { return {
@ -19,15 +26,3 @@ export class OrganizationRepositoryMockModule {
}; };
} }
} }
class OrganizationRepositoryMock implements IRepository<IOrganization> {
getBy(filter: (model: IOrganization) => boolean): Promise<IOrganization[]> {
throw new Error("Method not implemented.");
}
save(models: IOrganization[]): Promise<IOrganization[]> {
throw new Error("Method not implemented.");
}
deleteBy(filter: (model: IOrganization) => boolean): Promise<boolean> {
throw new Error("Method not implemented.");
}
}

View File

@ -1,12 +1,21 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { IPasswordService } from "../src"; import {
APIHUB24_PASSWORD_SERVICE,
IPasswordService,
} from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
export class PasswordServiceMockModule { export class PasswordServiceMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ provide: "@apihub24/password_service", useClass: PasswordServiceMock }, {
provide: APIHUB24_PASSWORD_SERVICE,
useValue: {
hash: jest.fn(),
verify: jest.fn(),
} as IPasswordService,
},
]; ];
return { return {
module: PasswordServiceMockModule, module: PasswordServiceMockModule,
@ -15,12 +24,3 @@ export class PasswordServiceMockModule {
}; };
} }
} }
class PasswordServiceMock implements IPasswordService {
hash(plainTextPassword: string): Promise<string> {
throw new Error("Method not implemented.");
}
verify(plainTextPassword: string, passwordHash: string): Promise<boolean> {
throw new Error("Method not implemented.");
}
}

View File

@ -1,6 +1,6 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { IRight } from "../src";
import { IRepository } from "@apihub24/repository"; import { IRepository } from "@apihub24/repository";
import { APIHUB24_RIGHT_REPOSITORY, IRight } from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
@ -8,8 +8,12 @@ export class RightRepositoryMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ {
provide: "@apihub24/right_repository", provide: APIHUB24_RIGHT_REPOSITORY,
useClass: RightRepositoryMock, useValue: {
getBy: jest.fn(),
deleteBy: jest.fn(),
save: jest.fn(),
} as IRepository<IRight>,
}, },
]; ];
return { return {
@ -19,15 +23,3 @@ export class RightRepositoryMockModule {
}; };
} }
} }
class RightRepositoryMock implements IRepository<IRight> {
getBy(filter: (model: IRight) => boolean): Promise<IRight[]> {
throw new Error("Method not implemented.");
}
save(models: IRight[]): Promise<IRight[]> {
throw new Error("Method not implemented.");
}
deleteBy(filter: (model: IRight) => boolean): Promise<boolean> {
throw new Error("Method not implemented.");
}
}

View File

@ -1,12 +1,23 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { IAccount, ISession, ISessionService } from "../src"; import {
APIHUB24_SESSION_SERVICE,
ISessionService,
} from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
export class SessionServiceMockModule { export class SessionServiceMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ provide: "@apihub24/session_service", useClass: SessionServiceMock }, {
provide: APIHUB24_SESSION_SERVICE,
useValue: {
create: jest.fn(),
getBy: jest.fn(),
getById: jest.fn(),
remove: jest.fn(),
} as ISessionService,
},
]; ];
return { return {
module: SessionServiceMockModule, module: SessionServiceMockModule,
@ -15,18 +26,3 @@ export class SessionServiceMockModule {
}; };
} }
} }
class SessionServiceMock implements ISessionService {
create(account: IAccount): Promise<ISession> {
throw new Error("Method not implemented.");
}
getBy(filter: (account: IAccount) => boolean): Promise<ISession[]> {
throw new Error("Method not implemented.");
}
getById(sessionId: string): Promise<ISession | null> {
throw new Error("Method not implemented.");
}
remove(sessionId: string): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@ -1,12 +1,22 @@
import { DynamicModule, Global, Module } from "@nestjs/common"; import { DynamicModule, Global, Module } from "@nestjs/common";
import { Algorithm, IAccount, ISession, ITokenService } from "../src"; import {
APIHUB24_TOKEN_SERVICE,
ITokenService,
} from "@apihub24/authentication";
@Global() @Global()
@Module({}) @Module({})
export class TokenServiceMockModule { export class TokenServiceMockModule {
static forRoot(): DynamicModule { static forRoot(): DynamicModule {
const providers = [ const providers = [
{ provide: "@apihub24/token_service", useClass: TokenServiceMock }, {
provide: APIHUB24_TOKEN_SERVICE,
useValue: {
generate: jest.fn(),
getAccount: jest.fn(),
validate: jest.fn(),
} as ITokenService,
},
]; ];
return { return {
module: TokenServiceMockModule, module: TokenServiceMockModule,
@ -15,20 +25,3 @@ export class TokenServiceMockModule {
}; };
} }
} }
class TokenServiceMock implements ITokenService {
generate(
session: ISession,
subject: string,
expires?: string,
algorithm?: Algorithm
): Promise<string> {
throw new Error("Method not implemented.");
}
validate(token: string): Promise<boolean> {
throw new Error("Method not implemented.");
}
getAccount(token: string): Promise<IAccount | null> {
throw new Error("Method not implemented.");
}
}