add new tests
This commit is contained in:
parent
acdbc9d402
commit
1d9f3e8d5f
12
package-lock.json
generated
12
package-lock.json
generated
@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "@apihub24/token-authentication",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@apihub24/token-authentication",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apihub24/authentication": "^1.0.1",
|
||||
"@apihub24/authentication": "2.0.0-alpha.0",
|
||||
"@apihub24/repository": "^1.0.3",
|
||||
"@apihub24/translation": "^1.0.1",
|
||||
"@nestjs/common": "^11.1.6",
|
||||
@ -42,9 +42,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@apihub24/authentication": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@apihub24/authentication/-/authentication-1.0.1.tgz",
|
||||
"integrity": "sha512-nWw75ofQKHxE0dI7PzvNBQNcQrX/HSrzuAJTYNu42BoCROba1NUz8QAodTn5+3dIeQEzw127gtSb6D7yW0B8Jg==",
|
||||
"version": "2.0.0-alpha.0",
|
||||
"resolved": "https://registry.npmjs.org/@apihub24/authentication/-/authentication-2.0.0-alpha.0.tgz",
|
||||
"integrity": "sha512-e7ZGD2fHSo2LJFuu9/6lJ4JMq52anK1jUe5btusVbNRzAP+8lrFcwytlctLUF2Adtlg/DgLGrLzCgSm+g19TVw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@apihub24/repository": {
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
{
|
||||
"name": "@apihub24/token-authentication",
|
||||
"version": "1.0.5",
|
||||
"version": "2.0.0-alpha.0",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "rimraf ./dist && tsc",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:coverage": "jest --coverage",
|
||||
"pub": "npm publish",
|
||||
"rel": "npm i && npm run build && npm run test:coverage"
|
||||
@ -15,7 +16,7 @@
|
||||
"@nestjs/common": "^11.1.6",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.1.6",
|
||||
"@apihub24/authentication": "^1.0.1",
|
||||
"@apihub24/authentication": "2.0.0-alpha.0",
|
||||
"@apihub24/repository": "^1.0.3",
|
||||
"@apihub24/translation": "^1.0.1",
|
||||
"class-validator": "^0.14.2",
|
||||
|
||||
@ -23,7 +23,7 @@ export class TokenGuard implements CanActivate {
|
||||
*/
|
||||
constructor(
|
||||
private reflector: Reflector,
|
||||
@Inject("@apihub24/token_service")
|
||||
@Inject(authentication.APIHUB24_TOKEN_SERVICE)
|
||||
private readonly tokenService: authentication.ITokenService
|
||||
) {}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
} from "../";
|
||||
import {
|
||||
APIHUB24_PASSWORD_SERVICE,
|
||||
IPasswordService,
|
||||
IRegistration,
|
||||
} from "@apihub24/authentication";
|
||||
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 { Group } from "../models/group";
|
||||
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", () => {
|
||||
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 () => {
|
||||
// create testing module
|
||||
module = await Test.createTestingModule({
|
||||
imports: [
|
||||
MailServiceMockModule.forRoot(),
|
||||
@ -35,42 +76,72 @@ describe("AccountFactoryService Tests", () => {
|
||||
OrganizationRepositoryMockModule.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();
|
||||
const service = module?.get(AccountFactoryService);
|
||||
const groupService = module?.get(GroupService);
|
||||
const passwordService = module?.get(APIHUB24_PASSWORD_SERVICE);
|
||||
expect(service).toBeDefined();
|
||||
expect(groupService).toBeDefined();
|
||||
expect(passwordService).toBeDefined();
|
||||
expect(groupService).toBeDefined();
|
||||
});
|
||||
|
||||
const adminGroup = new Group();
|
||||
adminGroup.id = "1";
|
||||
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);
|
||||
it("should create inactive Account from Registration with unverified Email", async () => {
|
||||
const user = await service.createFromRegistration(mockedRegistration);
|
||||
expect(user).toBeDefined();
|
||||
expect(user?.accountName).toBe(registration.accountName);
|
||||
expect(user?.email).toBe(registration.email);
|
||||
expect(user?.passwordHash).toBe(registration.password);
|
||||
expect(user?.emailVerified).toBeFalsy();
|
||||
expect(user?.active).toBeFalsy();
|
||||
expect(user.accountName).toBe(mockedRegistration.accountName);
|
||||
expect(user.email).toBe(mockedRegistration.email);
|
||||
expect(user.passwordHash).toBe(mockedPasswordHash);
|
||||
expect(user.emailVerified).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
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
230
src/services/account.service.spec.ts
Normal file
230
src/services/account.service.spec.ts
Normal 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"));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -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 { Inject, Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class AccountService {
|
||||
constructor(
|
||||
@Inject("@apihub24/account_repository")
|
||||
@Inject(APIHUB24_ACCOUNT_REPOSITORY)
|
||||
private readonly accountRepository: repository.IRepository<IAccount>,
|
||||
@Inject("@apihub24/group_repository")
|
||||
@Inject(APIHUB24_GROUP_REPOSITORY)
|
||||
private readonly groupRepository: repository.IRepository<IGroup>
|
||||
) {}
|
||||
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
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()
|
||||
export class GroupService {
|
||||
constructor(
|
||||
@Inject("@apihub24/group_repository")
|
||||
@Inject(APIHUB24_GROUP_REPOSITORY)
|
||||
private readonly groupRepository: repository.IRepository<IGroup>,
|
||||
@Inject("@apihub24/right_repository")
|
||||
@Inject(APIHUB24_RIGHT_REPOSITORY)
|
||||
private readonly rightRepository: repository.IRepository<IRight>
|
||||
) {}
|
||||
|
||||
|
||||
@ -5,11 +5,11 @@ import * as authentication from "@apihub24/authentication";
|
||||
@Injectable()
|
||||
export class LoginService {
|
||||
constructor(
|
||||
@Inject("@apihub24/token_service")
|
||||
@Inject(authentication.APIHUB24_TOKEN_SERVICE)
|
||||
private readonly tokenService: authentication.ITokenService,
|
||||
@Inject("@apihub24/password_service")
|
||||
@Inject(authentication.APIHUB24_PASSWORD_SERVICE)
|
||||
private readonly passwordService: authentication.IPasswordService,
|
||||
@Inject("@apihub24/session_service")
|
||||
@Inject(authentication.APIHUB24_SESSION_SERVICE)
|
||||
private readonly sessionService: authentication.ISessionService,
|
||||
@Inject(AccountService)
|
||||
private readonly accountService: AccountService
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import * as repository from "@apihub24/repository";
|
||||
import { IOrganization } from "@apihub24/authentication";
|
||||
import {
|
||||
APIHUB24_ORGANIZATION_REPOSITORY,
|
||||
IOrganization,
|
||||
} from "@apihub24/authentication";
|
||||
|
||||
@Injectable()
|
||||
export class OrganizationService {
|
||||
constructor(
|
||||
@Inject("@apihub24/organization_repository")
|
||||
@Inject(APIHUB24_ORGANIZATION_REPOSITORY)
|
||||
private readonly organizationRepository: repository.IRepository<IOrganization>
|
||||
) {}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ export class RegistrationService {
|
||||
private readonly accountService: AccountService,
|
||||
@Inject(AccountFactoryService)
|
||||
private readonly accountFactory: AccountFactoryService,
|
||||
@Inject("@apihub24/mail_verification_service")
|
||||
@Inject(authentication.APIHUB24_MAIL_SERVICE)
|
||||
private readonly mailVerificationService: authentication.IMailVerificationService
|
||||
) {}
|
||||
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import * as repository from "@apihub24/repository";
|
||||
import { IRight } from "@apihub24/authentication";
|
||||
import { APIHUB24_RIGHT_REPOSITORY, IRight } from "@apihub24/authentication";
|
||||
|
||||
@Injectable()
|
||||
export class RightService {
|
||||
constructor(
|
||||
@Inject("@apihub24/right_repository")
|
||||
@Inject(APIHUB24_RIGHT_REPOSITORY)
|
||||
private readonly rightRepository: repository.IRepository<IRight>
|
||||
) {}
|
||||
|
||||
|
||||
@ -65,44 +65,4 @@ describe("TokenAuthenticationModule Tests", () => {
|
||||
expect(module).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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { IAccount } from "../src";
|
||||
import { IRepository } from "@apihub24/repository";
|
||||
import {
|
||||
APIHUB24_ACCOUNT_REPOSITORY,
|
||||
IAccount,
|
||||
} from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
@ -8,8 +11,12 @@ export class AccountRepositoryMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const providers = [
|
||||
{
|
||||
provide: "@apihub24/account_repository",
|
||||
useClass: AccountRepositoryMock,
|
||||
provide: APIHUB24_ACCOUNT_REPOSITORY,
|
||||
useValue: {
|
||||
deleteBy: jest.fn(),
|
||||
getBy: jest.fn(),
|
||||
save: jest.fn(),
|
||||
} as IRepository<IAccount>,
|
||||
},
|
||||
];
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { IGroup } from "../src";
|
||||
import { IRepository } from "@apihub24/repository";
|
||||
import { APIHUB24_GROUP_REPOSITORY, IGroup } from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
@ -8,8 +8,12 @@ export class GroupRepositoryMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const providers = [
|
||||
{
|
||||
provide: "@apihub24/group_repository",
|
||||
useClass: GroupRepositoryMock,
|
||||
provide: APIHUB24_GROUP_REPOSITORY,
|
||||
useValue: {
|
||||
deleteBy: jest.fn(),
|
||||
getBy: jest.fn(),
|
||||
save: jest.fn(),
|
||||
} as IRepository<IGroup>,
|
||||
},
|
||||
];
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { IAccount, ISession, IMailVerificationService } from "../src";
|
||||
import {
|
||||
APIHUB24_MAIL_SERVICE,
|
||||
IMailVerificationService,
|
||||
} from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
@ -7,8 +10,11 @@ export class MailServiceMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const providers = [
|
||||
{
|
||||
provide: "@apihub24/mail_verification_service",
|
||||
useClass: MailServiceMock,
|
||||
provide: APIHUB24_MAIL_SERVICE,
|
||||
useValue: {
|
||||
sendVerificationMail: jest.fn(),
|
||||
verify: jest.fn(),
|
||||
} as IMailVerificationService,
|
||||
},
|
||||
];
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { IOrganization } from "../src";
|
||||
import { IRepository } from "@apihub24/repository";
|
||||
import {
|
||||
APIHUB24_ORGANIZATION_REPOSITORY,
|
||||
IOrganization,
|
||||
} from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
@ -8,8 +11,12 @@ export class OrganizationRepositoryMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const providers = [
|
||||
{
|
||||
provide: "@apihub24/organization_repository",
|
||||
useClass: OrganizationRepositoryMock,
|
||||
provide: APIHUB24_ORGANIZATION_REPOSITORY,
|
||||
useValue: {
|
||||
deleteBy: jest.fn(),
|
||||
getBy: jest.fn(),
|
||||
save: jest.fn(),
|
||||
} as IRepository<IOrganization>,
|
||||
},
|
||||
];
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,21 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { IPasswordService } from "../src";
|
||||
import {
|
||||
APIHUB24_PASSWORD_SERVICE,
|
||||
IPasswordService,
|
||||
} from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
export class PasswordServiceMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const providers = [
|
||||
{ provide: "@apihub24/password_service", useClass: PasswordServiceMock },
|
||||
{
|
||||
provide: APIHUB24_PASSWORD_SERVICE,
|
||||
useValue: {
|
||||
hash: jest.fn(),
|
||||
verify: jest.fn(),
|
||||
} as IPasswordService,
|
||||
},
|
||||
];
|
||||
return {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { IRight } from "../src";
|
||||
import { IRepository } from "@apihub24/repository";
|
||||
import { APIHUB24_RIGHT_REPOSITORY, IRight } from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
@ -8,8 +8,12 @@ export class RightRepositoryMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const providers = [
|
||||
{
|
||||
provide: "@apihub24/right_repository",
|
||||
useClass: RightRepositoryMock,
|
||||
provide: APIHUB24_RIGHT_REPOSITORY,
|
||||
useValue: {
|
||||
getBy: jest.fn(),
|
||||
deleteBy: jest.fn(),
|
||||
save: jest.fn(),
|
||||
} as IRepository<IRight>,
|
||||
},
|
||||
];
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,23 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { IAccount, ISession, ISessionService } from "../src";
|
||||
import {
|
||||
APIHUB24_SESSION_SERVICE,
|
||||
ISessionService,
|
||||
} from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
export class SessionServiceMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
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 {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,22 @@
|
||||
import { DynamicModule, Global, Module } from "@nestjs/common";
|
||||
import { Algorithm, IAccount, ISession, ITokenService } from "../src";
|
||||
import {
|
||||
APIHUB24_TOKEN_SERVICE,
|
||||
ITokenService,
|
||||
} from "@apihub24/authentication";
|
||||
|
||||
@Global()
|
||||
@Module({})
|
||||
export class TokenServiceMockModule {
|
||||
static forRoot(): DynamicModule {
|
||||
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 {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user