Feature/services tests (#21)
This commit is contained in:
commit
806e15f2db
@ -1,4 +1,7 @@
|
||||
DATABASE_URL="postgresql://prisma:prisma@localhost:5433/tests"
|
||||
POSTGRES_USER=prisma
|
||||
POSTGRES_PASSWORD=prisma
|
||||
POSTGRES_DB=tests
|
||||
DATABASE_PORT="5433"
|
||||
DATABASE_USER="prisma"
|
||||
DATABASE_PASSWORD="prisma"
|
||||
DATABASE_NAME="tests"
|
||||
DATABASE_HOSTNAME="localhost"
|
||||
DEV_PRISMA_STUDIO_DB_URL="postgresql://prisma:prisma@localhost:5433/tests"
|
@ -25,11 +25,12 @@
|
||||
"api:dev": "nodemon",
|
||||
"build:test": "tsc && mocha ./dist/entries/Test.js",
|
||||
"format": "prettier --write src",
|
||||
"migrate:test": "dotenv -e .env.test -- npx prisma migrate deploy",
|
||||
"migrate": "npx prisma migrate deploy",
|
||||
"docker:up": "docker-compose up -d",
|
||||
"docker:up:test": "docker-compose -f docker-compose-test.yml up -d",
|
||||
"docker:down": "docker-compose -f docker-compose-test.yml down",
|
||||
"test": "tsc && npm run docker:up:test && npm run migrate && jest -i --verbose ./dist/test/* && npm run docker:down"
|
||||
"test": "tsc && npm run docker:up:test && npm run migrate:test && dotenv -e .env.test -- jest -i --verbose ./dist/test/* && npm run docker:down"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -47,10 +48,9 @@
|
||||
"class-validator": "^0.14.0",
|
||||
"classnames": "^2.3.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.21",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.24",
|
||||
"module-alias": "^2.2.2",
|
||||
"next": "^13.1.5",
|
||||
"node-cache": "^5.1.2",
|
||||
@ -71,6 +71,7 @@
|
||||
"@types/node": "^18.11.18",
|
||||
"@types/node-schedule": "^2.1.0",
|
||||
"@types/uuid": "^9.0.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"jest": "^29.5.0",
|
||||
"nodemon": "^2.0.20",
|
||||
"prettier": "2.8.4",
|
||||
|
@ -137,6 +137,7 @@ model OfficeFolders {
|
||||
office_folder_has_stakeholder OfficeFolderHasStakeholders[]
|
||||
documents Documents[]
|
||||
|
||||
@@unique([folder_number, office_uuid])
|
||||
@@map("office_folders")
|
||||
}
|
||||
|
||||
@ -149,7 +150,7 @@ model OfficeFolderHasCustomers {
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
|
||||
@@unique([customer_uuid, office_folder_uuid])
|
||||
@@unique([office_folder_uuid, customer_uuid])
|
||||
@@map("office_folder_has_customers")
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Customers, ECivility, ECustomerStatus } from "@prisma/client";
|
||||
import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -28,7 +28,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
* @description : Create a customer
|
||||
*/
|
||||
public async create(customer: Customer): Promise<Customers> {
|
||||
return this.model.create({
|
||||
const createArgs: Prisma.CustomersCreateArgs = {
|
||||
data: {
|
||||
status: ECustomerStatus.PENDING,
|
||||
contact: {
|
||||
@ -39,24 +39,27 @@ export default class CustomersRepository extends BaseRepository {
|
||||
phone_number: customer.contact.phone_number,
|
||||
cell_phone_number: customer.contact?.cell_phone_number,
|
||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
||||
address: {
|
||||
create: {
|
||||
address: customer.contact.address?.address,
|
||||
zip_code: customer.contact.address.zip_code,
|
||||
city: customer.contact.address.city,
|
||||
},
|
||||
},
|
||||
address: {}
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (customer.contact.address) {
|
||||
createArgs.data.contact!.create!.address!.create = {
|
||||
address: customer.contact.address!.address,
|
||||
zip_code: customer.contact.address!.zip_code,
|
||||
city: customer.contact.address!.city,
|
||||
};
|
||||
}
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data from a customer
|
||||
*/
|
||||
public async update(uid: string, customer: Customer): Promise<Customers> {
|
||||
return this.model.update({
|
||||
const updateArgs: Prisma.CustomersUpdateArgs = {
|
||||
where: {
|
||||
uuid: uid,
|
||||
},
|
||||
@ -70,17 +73,19 @@ export default class CustomersRepository extends BaseRepository {
|
||||
phone_number: customer.contact.phone_number,
|
||||
cell_phone_number: customer.contact.cell_phone_number,
|
||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
||||
address: {
|
||||
update: {
|
||||
address: customer.contact.address.address,
|
||||
zip_code: customer.contact.address.zip_code,
|
||||
city: customer.contact.address.city,
|
||||
},
|
||||
},
|
||||
address: {}
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
if (customer.contact.address) {
|
||||
updateArgs.data.contact!.update!.address!.update = {
|
||||
address: customer.contact.address!.address,
|
||||
zip_code: customer.contact.address!.zip_code,
|
||||
city: customer.contact.address!.city,
|
||||
};
|
||||
}
|
||||
return this.model.update(updateArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
* @description : Create new deed type
|
||||
*/
|
||||
public async create(deedType: DeedType): Promise<DeedTypes> {
|
||||
return this.model.create({
|
||||
const createArgs: Prisma.DeedTypesCreateArgs = {
|
||||
data: {
|
||||
name: deedType.name,
|
||||
description: deedType.description,
|
||||
@ -37,8 +37,19 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
uuid: deedType.office.uid,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
if (deedType.deed_type_has_document_types) {
|
||||
createArgs.data.deed_type_has_document_types = {
|
||||
createMany: {
|
||||
data: deedType.deed_type_has_document_types.map((relation) => ({
|
||||
document_type_uuid: relation.document_type.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +79,7 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
deleteMany: { deed_type_uuid: uid },
|
||||
createMany: {
|
||||
data: deedType.deed_type_has_document_types.map((relation) => ({
|
||||
document_type_uuid: relation.document_type.uid,
|
||||
document_type_uuid: relation.document_type.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
|
@ -28,7 +28,7 @@ export default class DeedsRepository extends BaseRepository {
|
||||
* @description : Create a deed based on a deed type
|
||||
*/
|
||||
public async create(deed: Deed): Promise<Deeds> {
|
||||
return this.model.create({
|
||||
const createArgs: Prisma.DeedsCreateArgs = {
|
||||
data: {
|
||||
deed_type: {
|
||||
connect: {
|
||||
@ -36,7 +36,27 @@ export default class DeedsRepository extends BaseRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const deedTypeWithDocumentTypes = await this.instanceDb.deedTypes.findUniqueOrThrow({
|
||||
where: {
|
||||
uuid: deed.deed_type.uid,
|
||||
},
|
||||
include: { deed_type_has_document_types: true },
|
||||
});
|
||||
|
||||
if (deedTypeWithDocumentTypes.archived_at) throw new Error("deed type is archived");
|
||||
|
||||
if (deedTypeWithDocumentTypes.deed_type_has_document_types) {
|
||||
createArgs.data.deed_has_document_types = {
|
||||
createMany: {
|
||||
data: deedTypeWithDocumentTypes.deed_type_has_document_types.map((relation) => ({
|
||||
document_type_uuid: relation.document_type_uuid,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,7 +77,7 @@ export default class DeedsRepository extends BaseRepository {
|
||||
deleteMany: { deed_uuid: uid },
|
||||
createMany: {
|
||||
data: deed.deed_has_document_types.map((relation) => ({
|
||||
document_type_uuid: relation.document_type.uid,
|
||||
document_type_uuid: relation.document_type.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
|
@ -67,9 +67,9 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
public async createMany(documents: Document[]): Promise<Prisma.BatchPayload> {
|
||||
return this.model.createMany({
|
||||
data: documents.map((document) => ({
|
||||
folder_uuid: document.folder.uid,
|
||||
depositor_uuid: document.depositor.uid,
|
||||
document_type_uuid: document.document_type.uid,
|
||||
folder_uuid: document.folder.uid!,
|
||||
depositor_uuid: document.depositor.uid!,
|
||||
document_type_uuid: document.document_type.uid!,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
@ -25,7 +25,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create new office folder without customers nor stakeholders
|
||||
* @description : Create new office folder with stakeholders
|
||||
*/
|
||||
public async create(officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||
const createArgs: Prisma.OfficeFoldersCreateArgs = {
|
||||
@ -57,7 +57,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
createArgs.data.office_folder_has_stakeholder = {
|
||||
createMany: {
|
||||
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
|
||||
user_stakeholder_uuid: relation.user_stakeholder.uid,
|
||||
user_stakeholder_uuid: relation.user_stakeholder.uid!,
|
||||
})),
|
||||
skipDuplicates: true
|
||||
},
|
||||
@ -92,7 +92,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
deleteMany: { office_folder_uuid: officeFolderUuid },
|
||||
createMany: {
|
||||
data: officeFolder.office_folder_has_stakeholder.map((relation) => ({
|
||||
user_stakeholder_uuid: relation.user_stakeholder.uid,
|
||||
user_stakeholder_uuid: relation.user_stakeholder.uid!,
|
||||
})),
|
||||
skipDuplicates: true
|
||||
},
|
||||
@ -103,7 +103,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
deleteMany: { office_folder_uuid: officeFolderUuid },
|
||||
createMany: {
|
||||
data: officeFolder.office_folder_has_customers.map((relation) => ({
|
||||
customer_uuid: relation.customer.uid,
|
||||
customer_uuid: relation.customer.uid!,
|
||||
})),
|
||||
skipDuplicates: true
|
||||
},
|
||||
@ -113,8 +113,8 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
updateArgs.data.documents = {
|
||||
createMany: {
|
||||
data: officeFolder.documents.map((relation) => ({
|
||||
document_type_uuid: relation.document_type.uid,
|
||||
depositor_uuid: relation.depositor.uid
|
||||
document_type_uuid: relation.document_type.uid!,
|
||||
depositor_uuid: relation.depositor.uid!
|
||||
})),
|
||||
skipDuplicates: true
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { ECivility, Users } from "@prisma/client";
|
||||
import { ECivility, Prisma, Users } from "@prisma/client";
|
||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -28,7 +28,7 @@ export default class UsersRepository extends BaseRepository {
|
||||
* @description : Create a user
|
||||
*/
|
||||
public async create(user: User): Promise<Users> {
|
||||
return this.model.create({
|
||||
const createArgs: Prisma.UsersCreateArgs = {
|
||||
data: {
|
||||
idNot: user.idNot,
|
||||
office_membership: {
|
||||
@ -58,24 +58,26 @@ export default class UsersRepository extends BaseRepository {
|
||||
phone_number: user.contact.phone_number,
|
||||
cell_phone_number: user.contact.cell_phone_number,
|
||||
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
||||
address: {
|
||||
create: {
|
||||
address: user.contact.address.address,
|
||||
zip_code: user.contact.address.zip_code,
|
||||
city: user.contact.address.city,
|
||||
},
|
||||
},
|
||||
address: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
if (user.contact.address) {
|
||||
createArgs.data.contact!.create!.address!.create = {
|
||||
address: user.contact.address!.address,
|
||||
zip_code: user.contact.address!.zip_code,
|
||||
city: user.contact.address!.city,
|
||||
};
|
||||
}
|
||||
return this.model.create(createArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data from a user
|
||||
*/
|
||||
public async update(uid: string, user: User): Promise<Users> {
|
||||
return this.model.update({
|
||||
const updateArgs: Prisma.UsersUpdateArgs = {
|
||||
where: {
|
||||
uuid: uid,
|
||||
},
|
||||
@ -108,17 +110,19 @@ export default class UsersRepository extends BaseRepository {
|
||||
phone_number: user.contact.phone_number,
|
||||
cell_phone_number: user.contact.cell_phone_number,
|
||||
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
||||
address: {
|
||||
update: {
|
||||
address: user.contact.address.address,
|
||||
zip_code: user.contact.address.zip_code,
|
||||
city: user.contact.address.city,
|
||||
},
|
||||
},
|
||||
address: {}
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
if (user.contact.address) {
|
||||
updateArgs.data.contact!.update!.address!.update = {
|
||||
address: user.contact.address!.address,
|
||||
zip_code: user.contact.address!.zip_code,
|
||||
city: user.contact.address!.city,
|
||||
};
|
||||
}
|
||||
return this.model.update(updateArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,12 +3,14 @@ import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "../DeedTypesService/DeedTypesService";
|
||||
|
||||
|
||||
@Service()
|
||||
export default class OfficeFoldersService extends BaseService {
|
||||
constructor(
|
||||
private officeFoldersRepository: OfficeFoldersRepository
|
||||
private officeFoldersRepository: OfficeFoldersRepository,
|
||||
private deedTypeService: DeedTypesService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@ -26,6 +28,8 @@ export default class OfficeFoldersService extends BaseService {
|
||||
* @throws {Error} If folder cannot be created
|
||||
*/
|
||||
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||
const deedType = await this.deedTypeService.getByUid(officeFolderEntity.deed.deed_type.uid!);
|
||||
if(deedType.archived_at) throw new Error('deed type is archived');
|
||||
return this.officeFoldersRepository.create(officeFolderEntity);
|
||||
}
|
||||
|
||||
|
121
src/test/config/Init.ts
Normal file
121
src/test/config/Init.ts
Normal file
@ -0,0 +1,121 @@
|
||||
import { Customers, DeedTypes, DocumentTypes, ECivility, ECustomerStatus, Offices, PrismaClient, Users } from "@prisma/client";
|
||||
import User, { Customer, DeedType, DocumentType, Office } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const initOffice = (office: Office): Promise<Offices> => {
|
||||
return prisma.offices.create({
|
||||
data: {
|
||||
idNot: office.idNot,
|
||||
name: office.name,
|
||||
crpcen: office.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: office.address.address,
|
||||
zip_code: office.address.zip_code,
|
||||
city: office.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const initDocumentType = (documentType: DocumentType, office: Office): Promise<DocumentTypes> => {
|
||||
return prisma.documentTypes.create({
|
||||
data: {
|
||||
name: documentType.name,
|
||||
public_description: documentType.public_description,
|
||||
private_description: documentType.private_description,
|
||||
archived_at: null,
|
||||
office_uuid: office.uid!,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const initDeedType = (deedType: DeedType, office: Office, documentTypes?: string[]): Promise<DeedTypes> => {
|
||||
return prisma.deedTypes.create({
|
||||
data: {
|
||||
name: deedType.name,
|
||||
description: deedType.description,
|
||||
archived_at: null,
|
||||
office_uuid: office.uid!,
|
||||
deed_type_has_document_types: {
|
||||
createMany: {
|
||||
data: documentTypes!.map((documentType) => ({
|
||||
document_type_uuid: documentType,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const initCustomers = (customer: Customer): Promise<Customers> => {
|
||||
return prisma.customers.create({
|
||||
data: {
|
||||
status: ECustomerStatus.PENDING,
|
||||
contact: {
|
||||
create: {
|
||||
first_name: customer.contact.first_name,
|
||||
last_name: customer.contact.last_name,
|
||||
email: customer.contact.email,
|
||||
phone_number: customer.contact.phone_number,
|
||||
cell_phone_number: customer.contact?.cell_phone_number,
|
||||
civility: ECivility[customer.contact.civility as keyof typeof ECivility],
|
||||
address: {
|
||||
create: {
|
||||
address: customer.contact.address!.address,
|
||||
zip_code: customer.contact.address!.zip_code,
|
||||
city: customer.contact.address!.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const initUsers = (user: User): Promise<Users> => {
|
||||
return prisma.users.create({
|
||||
data: {
|
||||
idNot: user.idNot,
|
||||
office_membership: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
idNot: user.office_membership.idNot,
|
||||
},
|
||||
create: {
|
||||
idNot: user.office_membership.idNot,
|
||||
name: user.office_membership.name,
|
||||
crpcen: user.office_membership.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: user.office_membership.address.address,
|
||||
zip_code: user.office_membership.address.zip_code,
|
||||
city: user.office_membership.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
contact: {
|
||||
create: {
|
||||
first_name: user.contact.first_name,
|
||||
last_name: user.contact.last_name,
|
||||
email: user.contact.email,
|
||||
phone_number: user.contact.phone_number,
|
||||
cell_phone_number: user.contact.cell_phone_number,
|
||||
civility: ECivility[user.contact.civility as keyof typeof ECivility],
|
||||
address: {
|
||||
create: {
|
||||
address: user.contact.address!.address,
|
||||
zip_code: user.contact.address!.zip_code,
|
||||
city: user.contact.address!.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
@ -2,7 +2,6 @@ import { EOfficeStatus } from "le-coffre-resources/dist/Customer/Office";
|
||||
import User, { Address, Contact, Office, DeedType, DocumentType, Customer, OfficeFolder, Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
export const userAddress: Address = {
|
||||
uid: "",
|
||||
address: "1 avenue des champs élysées",
|
||||
zip_code: 75008,
|
||||
city: "paris",
|
||||
@ -11,7 +10,6 @@ export const userAddress: Address = {
|
||||
};
|
||||
|
||||
export const userAddress_: Address = {
|
||||
uid: "",
|
||||
address: "1 rue Victor Hugo",
|
||||
zip_code: 75001,
|
||||
city: "paris",
|
||||
@ -20,7 +18,6 @@ export const userAddress_: Address = {
|
||||
};
|
||||
|
||||
export const userContact: Contact = {
|
||||
uid: "",
|
||||
first_name: "Philippe",
|
||||
last_name: "le Bel",
|
||||
address: userAddress,
|
||||
@ -33,7 +30,6 @@ export const userContact: Contact = {
|
||||
};
|
||||
|
||||
export const userContact_: Contact = {
|
||||
uid: "",
|
||||
first_name: "Saint",
|
||||
last_name: "Louise",
|
||||
address: userAddress_,
|
||||
@ -45,8 +41,31 @@ export const userContact_: Contact = {
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const customerContact: Contact = {
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
address: userAddress,
|
||||
email: "john.doe@customer.fr",
|
||||
phone_number: "+3313847505",
|
||||
cell_phone_number: "+3313847505",
|
||||
civility: "MALE",
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const customerContact_: Contact = {
|
||||
first_name: "Jocelyne",
|
||||
last_name: "Doe",
|
||||
address: userAddress,
|
||||
email: "jocelyne.doe@customer.fr",
|
||||
phone_number: "+331384894505",
|
||||
cell_phone_number: "+331384894505",
|
||||
civility: "FEMALE",
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const officeAddress: Address = {
|
||||
uid: "",
|
||||
address: "1 rue Rivoli",
|
||||
zip_code: 75001,
|
||||
city: "paris",
|
||||
@ -55,7 +74,6 @@ export const officeAddress: Address = {
|
||||
};
|
||||
|
||||
export const officeAddress_: Address = {
|
||||
uid: "",
|
||||
address: "1 rue de la paix",
|
||||
zip_code: 75008,
|
||||
city: "paris",
|
||||
@ -64,7 +82,6 @@ export const officeAddress_: Address = {
|
||||
};
|
||||
|
||||
export const office: Office = {
|
||||
uid: "",
|
||||
idNot: "123456789",
|
||||
name: "first office",
|
||||
crpcen: "0123456789CRPCEN",
|
||||
@ -75,7 +92,6 @@ export const office: Office = {
|
||||
};
|
||||
|
||||
export const office_: Office = {
|
||||
uid: "",
|
||||
idNot: "789101112",
|
||||
name: "second office",
|
||||
crpcen: "987654321CRPCEN",
|
||||
@ -86,7 +102,6 @@ export const office_: Office = {
|
||||
};
|
||||
|
||||
export const user: User = {
|
||||
uid: "",
|
||||
idNot: "123456_123456789",
|
||||
contact: userContact,
|
||||
office_membership: office,
|
||||
@ -95,7 +110,6 @@ export const user: User = {
|
||||
};
|
||||
|
||||
export const user_: User = {
|
||||
uid: "",
|
||||
idNot: "654321_789101112",
|
||||
contact: userContact_,
|
||||
office_membership: office_,
|
||||
@ -103,42 +117,7 @@ export const user_: User = {
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const deedType: DeedType = {
|
||||
uid: "",
|
||||
name: "Wedding",
|
||||
description: "we assume wedding involve two people",
|
||||
archived_at: null,
|
||||
office: office,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const deedType_: DeedType = {
|
||||
uid: "",
|
||||
name: "Inheritance",
|
||||
description: "we assume inheritance involve two people",
|
||||
archived_at: null,
|
||||
office: office,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const deed: Deed = {
|
||||
uid: "",
|
||||
deed_type: deedType,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const deed_: Deed = {
|
||||
uid: "",
|
||||
deed_type: deedType_,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const documentType: DocumentType = {
|
||||
uid: "",
|
||||
name: "Identity card",
|
||||
public_description: "your ID card delivered by your country of residence",
|
||||
private_description: "verify if this ID card is legit",
|
||||
@ -149,7 +128,6 @@ export const documentType: DocumentType = {
|
||||
};
|
||||
|
||||
export const documentType_: DocumentType = {
|
||||
uid: "",
|
||||
name: "Electricity bill",
|
||||
public_description: "an electricity bill payed within the last 3 months",
|
||||
private_description: "verify if this electricity company is legit",
|
||||
@ -159,24 +137,59 @@ export const documentType_: DocumentType = {
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const deedType: DeedType = {
|
||||
name: "Wedding",
|
||||
description: "we assume wedding involve two people",
|
||||
archived_at: null,
|
||||
office: office,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
deed_type_has_document_types: [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const deedType_: DeedType = {
|
||||
name: "Inheritance",
|
||||
description: "we assume inheritance involve two people",
|
||||
archived_at: null,
|
||||
office: office_,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const deed: Deed = {
|
||||
deed_type: deedType,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const deed_: Deed = {
|
||||
deed_type: deedType_,
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const customer: Customer = {
|
||||
uid: "",
|
||||
contact: userContact,
|
||||
contact: customerContact,
|
||||
status: "PENDING",
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const customer_: Customer = {
|
||||
uid: "",
|
||||
contact: userContact_,
|
||||
contact: customerContact_,
|
||||
status: "ERRONED",
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const officeFolder: OfficeFolder = {
|
||||
uid: "",
|
||||
name: "Dossier 1234567",
|
||||
folder_number: "1234567",
|
||||
description: "Dossier de mr Dupont",
|
||||
@ -184,12 +197,39 @@ export const officeFolder: OfficeFolder = {
|
||||
status: "ARCHIVED",
|
||||
deed: deed,
|
||||
office: office,
|
||||
office_folder_has_customers: [
|
||||
{
|
||||
customer: customer,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
customer: customer_,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
],
|
||||
office_folder_has_stakeholder: [
|
||||
{
|
||||
user_stakeholder: user,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
user_stakeholder: user_,
|
||||
office_folder: new OfficeFolder(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
],
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
};
|
||||
|
||||
export const officeFolder_: OfficeFolder = {
|
||||
uid: "",
|
||||
name: "Dossier 89101112",
|
||||
folder_number: "89101112",
|
||||
description: "Dossier de mme Dutunnel",
|
@ -3,7 +3,7 @@ import "reflect-metadata";
|
||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { customer, customer_, userContact, userContact_ } from "./MockedData";
|
||||
import { customer, customerContact, customerContact_, customer_ } from "@Test/config/MockedData";
|
||||
import Container from "typedi";
|
||||
import CustomersRepository from "@Repositories/CustomersRepository";
|
||||
|
||||
@ -38,9 +38,9 @@ describe("test create function", () => {
|
||||
|
||||
// verify if customer address is created in db
|
||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
|
||||
expect(addressForContactCreated?.address).toEqual(customer.contact.address.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(customer.contact.address.city);
|
||||
expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city);
|
||||
});
|
||||
|
||||
it("should not create an customer already created", async () => {
|
||||
@ -53,7 +53,7 @@ describe("test create function", () => {
|
||||
|
||||
it("should not create an new customer with an email already created", async () => {
|
||||
let newCustomer: Customer = JSON.parse(JSON.stringify(customer_));
|
||||
newCustomer.contact.email = userContact.email;
|
||||
newCustomer.contact.email = customerContact.email;
|
||||
|
||||
// try to create a new customer with already used email
|
||||
async function createCustomerWithDuplicateEmail() {
|
||||
@ -64,7 +64,7 @@ describe("test create function", () => {
|
||||
|
||||
it("should not create an customer with an phone number already created", async () => {
|
||||
let newCustomer: Customer = JSON.parse(JSON.stringify(customer_));
|
||||
newCustomer.contact.cell_phone_number = userContact.cell_phone_number;
|
||||
newCustomer.contact.cell_phone_number = customerContact.cell_phone_number;
|
||||
|
||||
// try to create a new customer with already used cellphone number
|
||||
async function duplicateCustomer() {
|
||||
@ -75,8 +75,8 @@ describe("test create function", () => {
|
||||
|
||||
it("should create an new customer if unique attributes differ from existing customers", async () => {
|
||||
let newCustomer: Customer = JSON.parse(JSON.stringify(customer));
|
||||
newCustomer.contact.email = userContact_.email;
|
||||
newCustomer.contact.cell_phone_number = userContact_.cell_phone_number;
|
||||
newCustomer.contact.email = customerContact_.email;
|
||||
newCustomer.contact.cell_phone_number = customerContact_.cell_phone_number;
|
||||
|
||||
const customerCreated = await CustomersServiceTest.create(newCustomer);
|
||||
|
||||
@ -93,9 +93,9 @@ describe("test create function", () => {
|
||||
|
||||
// verify if customer_ address is created in db
|
||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
|
||||
expect(addressForContactCreated?.address).toEqual(customer.contact.address.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(customer.contact.address.city);
|
||||
expect(addressForContactCreated?.address).toEqual(customer.contact.address?.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(customer.contact.address?.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(customer.contact.address?.city);
|
||||
});
|
||||
});
|
||||
|
||||
@ -119,15 +119,15 @@ describe("test update function", () => {
|
||||
|
||||
// verify if customer_ address is created in db
|
||||
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uuid: existingContact?.address_uuid } });
|
||||
expect(addressForExistingContact?.address).toEqual(customer_.contact.address.address);
|
||||
expect(addressForExistingContact?.zip_code).toEqual(customer_.contact.address.zip_code);
|
||||
expect(addressForExistingContact?.city).toEqual(customer_.contact.address.city);
|
||||
expect(addressForExistingContact?.address).toEqual(customer_.contact.address?.address);
|
||||
expect(addressForExistingContact?.zip_code).toEqual(customer_.contact.address?.zip_code);
|
||||
expect(addressForExistingContact?.city).toEqual(customer_.contact.address?.city);
|
||||
});
|
||||
|
||||
it("should not update an customer with an email already used", async () => {
|
||||
const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uuid;
|
||||
let updatedCustomer: Customer = JSON.parse(JSON.stringify(customer_));
|
||||
updatedCustomer.contact.email = userContact.email;
|
||||
updatedCustomer.contact.email = customerContact.email;
|
||||
|
||||
// try to create a new customer with already used email
|
||||
async function updateCustomerWithDuplicateEmail() {
|
||||
@ -139,7 +139,7 @@ describe("test update function", () => {
|
||||
it("should not update an customer with an phone number already used", async () => {
|
||||
const customerUid = (await prisma.customers.findFirstOrThrow({ where: { contact: { email: customer_.contact.email } } })).uuid;
|
||||
let updatedCustomer: Customer = JSON.parse(JSON.stringify(customer_));
|
||||
updatedCustomer.contact.cell_phone_number = userContact.cell_phone_number;
|
||||
updatedCustomer.contact.cell_phone_number = customerContact.cell_phone_number;
|
||||
|
||||
// try to create a new customer with already used email
|
||||
async function updateCustomerWithDuplicateEmail() {
|
||||
|
@ -2,86 +2,21 @@ import "module-alias/register";
|
||||
import "reflect-metadata";
|
||||
import { Deed } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DeedService from "@Services/super-admin/DeedsService/DeedsService";
|
||||
import { PrismaClient, Offices, DocumentTypes, DeedTypes, DeedTypeHasDocumentTypes } from "prisma/prisma-client";
|
||||
import { deed, deedType, documentType, office } from "./MockedData";
|
||||
import { PrismaClient } from "prisma/prisma-client";
|
||||
import { deed, deedType, documentType, documentType_, office } from "@Test/config/MockedData";
|
||||
import DeedsRepository from "@Repositories/DeedsRepository";
|
||||
import Container from "typedi";
|
||||
import { initDeedType, initDocumentType, initOffice } from "@Test/config/Init";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const DeedServiceTest = new DeedService(Container.get(DeedsRepository));
|
||||
|
||||
let office1: Offices;
|
||||
|
||||
let documentType1: DocumentTypes;
|
||||
//let documentType2: DocumentTypes;
|
||||
|
||||
let deedType1: DeedTypes;
|
||||
|
||||
let deedType1HasDocumentType1: DeedTypeHasDocumentTypes;
|
||||
|
||||
beforeAll(async () => {
|
||||
office1 = await prisma.offices.create({
|
||||
data: {
|
||||
idNot: office.idNot,
|
||||
name: office.name,
|
||||
crpcen: office.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: office.address.address,
|
||||
zip_code: office.address.zip_code,
|
||||
city: office.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
documentType1 = await prisma.documentTypes.create({
|
||||
data: {
|
||||
name: documentType.name,
|
||||
public_description: documentType.public_description,
|
||||
private_description: documentType.private_description,
|
||||
archived_at: null,
|
||||
office_uuid: office1.uuid,
|
||||
},
|
||||
});
|
||||
|
||||
// documentType2 = await prisma.documentTypes.create({
|
||||
// data: {
|
||||
// name: documentType_.name,
|
||||
// public_description: documentType_.public_description,
|
||||
// private_description: documentType_.private_description,
|
||||
// archived_at: null,
|
||||
// office_uuid: office1.uuid,
|
||||
// },
|
||||
// });
|
||||
|
||||
deedType1 = await prisma.deedTypes.create({
|
||||
data: {
|
||||
name: deedType.name,
|
||||
description: deedType.description,
|
||||
archived_at: null,
|
||||
office_uuid: office1.uuid,
|
||||
},
|
||||
});
|
||||
|
||||
deedType1HasDocumentType1 = await prisma.deedTypeHasDocumentTypes.create({
|
||||
data: {
|
||||
deed_type_uuid: deedType1.uuid,
|
||||
document_type_uuid: documentType1.uuid,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.deedTypes.update({
|
||||
where: { uuid: deedType1.uuid },
|
||||
data: {
|
||||
deed_type_has_document_types: {
|
||||
connect: {
|
||||
uuid: deedType1HasDocumentType1.uuid,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
office.uid = (await initOffice(office)).uuid;
|
||||
documentType.uid = (await initDocumentType(documentType, office)).uuid;
|
||||
documentType_.uid = (await initDocumentType(documentType_, office)).uuid;
|
||||
deedType.uid = (await initDeedType(deedType, office, [documentType.uid])).uuid;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@ -93,41 +28,43 @@ afterAll(async () => {
|
||||
|
||||
describe("test create function", () => {
|
||||
it("should not create a new deed if deed type is unknown", async () => {
|
||||
let deedWithoutDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed));
|
||||
deedWithoutDeedTypeUid.deed_type.uid = "random uuid";
|
||||
// try to create a new deed with unknown deed type
|
||||
async function createDeedWithUnknownDeedType() {
|
||||
await DeedServiceTest.create(deed);
|
||||
await DeedServiceTest.create(deedWithoutDeedTypeUid);
|
||||
}
|
||||
await expect(createDeedWithUnknownDeedType).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("should create a new deed based on existing deed type", async () => {
|
||||
let deedWithUid: Deed = JSON.parse(JSON.stringify(deed));
|
||||
deedWithUid.uid = deedType1.uuid;
|
||||
const deedCreated = await DeedServiceTest.create(deedWithUid);
|
||||
let deedWithDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed));
|
||||
deedWithDeedTypeUid.deed_type.uid = deedType.uid;
|
||||
const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid);
|
||||
|
||||
expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
||||
expect(deedCreated.deed_type_uuid).toEqual(deedType.uid);
|
||||
});
|
||||
|
||||
it("should have by default the same document types as its deed type ", async () => {
|
||||
const deedWithDocumentTypes = await prisma.deeds.findFirstOrThrow({ include: { deed_has_document_types: true } });
|
||||
expect(deedWithDocumentTypes.deed_has_document_types.length).toEqual(1);
|
||||
expect(deedWithDocumentTypes.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||
expect(deedWithDocumentTypes.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType.uid);
|
||||
});
|
||||
|
||||
it("should create a the same deed based on existing deed type", async () => {
|
||||
let deedWithUid: Deed = JSON.parse(JSON.stringify(deed));
|
||||
deedWithUid.uid = deedType1.uuid;
|
||||
const deedCreated = await DeedServiceTest.create(deedWithUid);
|
||||
let deedWithDeedTypeUid: Deed = JSON.parse(JSON.stringify(deed));
|
||||
deedWithDeedTypeUid.deed_type.uid = deedType.uid;
|
||||
const deedCreated = await DeedServiceTest.create(deedWithDeedTypeUid);
|
||||
|
||||
expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
||||
expect(deedCreated.deed_type_uuid).toEqual(deedType.uid);
|
||||
});
|
||||
|
||||
it("should not create a new deed based on archivated deed type", async () => {
|
||||
let deedArchivated: Deed = JSON.parse(JSON.stringify(deed));
|
||||
deedArchivated.uid = deedType1.uuid;
|
||||
deedArchivated.deed_type.uid = deedType.uid;
|
||||
|
||||
await prisma.deedTypes.update({
|
||||
where: { uuid: deedType1.uuid },
|
||||
where: { uuid: deedType.uid },
|
||||
data: {
|
||||
archived_at: new Date(Date.now()),
|
||||
},
|
||||
@ -141,112 +78,91 @@ describe("test create function", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// describe("test addDocumentTypes function", () => {
|
||||
// it("should add document types to a deed", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||
// await DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||
describe("test update function", () => {
|
||||
it("should add document types to a deed", async () => {
|
||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType.uid } })).uuid;
|
||||
let deedToUpdate: Deed = JSON.parse(JSON.stringify(deed));
|
||||
|
||||
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deed.deed_has_document_types.length).toEqual(2);
|
||||
// });
|
||||
deedToUpdate.deed_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
|
||||
// it("should not add document types to a deed type that already has those document types ", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// let deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||
await DeedServiceTest.update(deedUid, deedToUpdate);
|
||||
|
||||
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
||||
// await DeedServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||
const deedUpdated = await prisma.deeds.findFirstOrThrow({
|
||||
where: {
|
||||
uuid: deedUid,
|
||||
},
|
||||
include: {
|
||||
deed_has_document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedUpdated.deed_has_document_types.length).toEqual(2);
|
||||
});
|
||||
|
||||
// deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||
// });
|
||||
// });
|
||||
// describe("test removeDocumentTypes function", () => {
|
||||
// it("should remove document types from a deed type", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// const documentsToRemove = [documentType1.uuid];
|
||||
// await DeedServiceTest.removeDocumentTypes(deedUid, documentsToRemove);
|
||||
it("should not add document types to a deed type that already has those document types ", async () => {
|
||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType.uid } })).uuid;
|
||||
let deedToUpdate: Deed = JSON.parse(JSON.stringify(deed));
|
||||
|
||||
// const deedWithDocumentTypeRelations = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithDocumentTypeRelations.deed_has_document_types.length).toEqual(1);
|
||||
// expect(deedWithDocumentTypeRelations.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
||||
// });
|
||||
// it("should not remove document types from a deed type is they were not linked", async () => {
|
||||
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||
// where: { deed_type_uuid: deedType1.uuid },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||
deedToUpdate.deed_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed: new Deed(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
|
||||
// const documentsToRemove = [documentType1.uuid];
|
||||
await DeedServiceTest.update(deedUid, deedToUpdate);
|
||||
|
||||
// async function removeDocumentTypeNotLinkedToDeedType() {
|
||||
// await DeedServiceTest.removeDocumentTypes(deedWithOneDocumentType.uuid, documentsToRemove);
|
||||
// }
|
||||
// await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
||||
// });
|
||||
// });
|
||||
// describe("test removeDocumentType function", () => {
|
||||
// it("should remove only one document type from a deed type", async () => {
|
||||
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||
// where: { deed_type_uuid: deedType1.uuid },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||
const deedUpdated = await prisma.deeds.findFirstOrThrow({
|
||||
where: {
|
||||
uuid: deedUid,
|
||||
},
|
||||
include: {
|
||||
deed_has_document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedUpdated.deed_has_document_types.length).toEqual(2);
|
||||
});
|
||||
|
||||
// const documentToRemove = documentType2.uuid;
|
||||
// await DeedServiceTest.removeDocumentType(deedWithOneDocumentType.uuid, documentToRemove);
|
||||
it("should delete document types from a deed", async () => {
|
||||
const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType.uid } })).uuid;
|
||||
let deedToUpdate: Deed = JSON.parse(JSON.stringify(deed));
|
||||
|
||||
// deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedWithOneDocumentType.uuid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(0);
|
||||
// });
|
||||
// });
|
||||
// describe("test addDocumentType function", () => {
|
||||
// it("should add only one document type to a deed type", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// const documentToAdd = documentType1.uuid;
|
||||
// await DeedServiceTest.addDocumentType(deedUid, documentToAdd);
|
||||
// set relation between deed and document types empty
|
||||
deedToUpdate.deed_has_document_types = [];
|
||||
|
||||
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deed.deed_has_document_types.length).toEqual(1);
|
||||
// expect(deed.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||
// });
|
||||
// });
|
||||
await DeedServiceTest.update(deedUid, deedToUpdate);
|
||||
|
||||
const deedUpdated = await prisma.deeds.findFirstOrThrow({
|
||||
where: {
|
||||
uuid: deedUid,
|
||||
},
|
||||
include: {
|
||||
deed_has_document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedUpdated.deed_has_document_types.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("test get function", () => {
|
||||
it("should return an array of Deeds", async () => {
|
||||
@ -257,7 +173,7 @@ describe("test get function", () => {
|
||||
expect(deeds.length).toEqual(2);
|
||||
|
||||
// verify result content
|
||||
expect(deeds[0]?.deed_type_uuid).toEqual(deedType1.uuid);
|
||||
expect(deeds[1]?.deed_type_uuid).toEqual(deedType1.uuid);
|
||||
expect(deeds[0]?.deed_type_uuid).toEqual(deedType.uid);
|
||||
expect(deeds[1]?.deed_type_uuid).toEqual(deedType.uid);
|
||||
});
|
||||
});
|
||||
|
@ -2,71 +2,21 @@ import "module-alias/register";
|
||||
import "reflect-metadata";
|
||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DeedTypeService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
||||
import { PrismaClient, Offices } from "prisma/prisma-client";
|
||||
import { deedType, deedType_, office, office_ } from "./MockedData";
|
||||
import { PrismaClient } from "prisma/prisma-client";
|
||||
import { deedType, deedType_, documentType, documentType_, office, office_ } from "@Test/config/MockedData";
|
||||
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
||||
import Container from "typedi";
|
||||
import { initDocumentType, initOffice } from "@Test/config/Init";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const DeedTypeServiceTest = new DeedTypeService(Container.get(DeedTypesRepository));
|
||||
|
||||
let office1: Offices;
|
||||
let office2: Offices;
|
||||
|
||||
// let documentType1: DocumentTypes;
|
||||
// let documentType2: DocumentTypes;
|
||||
|
||||
beforeAll(async () => {
|
||||
office1 = await prisma.offices.create({
|
||||
data: {
|
||||
idNot: office.idNot,
|
||||
name: office.name,
|
||||
crpcen: office.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: office.address.address,
|
||||
zip_code: office.address.zip_code,
|
||||
city: office.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
office2 = await prisma.offices.create({
|
||||
data: {
|
||||
idNot: office_.idNot,
|
||||
name: office_.name,
|
||||
crpcen: office_.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: office_.address.address,
|
||||
zip_code: office_.address.zip_code,
|
||||
city: office_.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// documentType1 = await prisma.documentTypes.create({
|
||||
// data: {
|
||||
// name: documentType.name,
|
||||
// public_description: documentType.public_description,
|
||||
// private_description: documentType.private_description,
|
||||
// archived_at: null,
|
||||
// office_uuid: office1.uuid,
|
||||
// },
|
||||
// });
|
||||
|
||||
// documentType2 = await prisma.documentTypes.create({
|
||||
// data: {
|
||||
// name: documentType_.name,
|
||||
// public_description: documentType_.public_description,
|
||||
// private_description: documentType_.private_description,
|
||||
// archived_at: null,
|
||||
// office_uuid: office1.uuid,
|
||||
// },
|
||||
// });
|
||||
office.uid = (await initOffice(office)).uuid;
|
||||
office_.uid = (await initOffice(office_)).uuid;
|
||||
documentType.uid = (await initDocumentType(documentType, office)).uuid;
|
||||
documentType_.uid = (await initDocumentType(documentType_, office)).uuid;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@ -78,27 +28,27 @@ afterAll(async () => {
|
||||
|
||||
describe("test create function", () => {
|
||||
it("should not create a new deed type if office is unknown", async () => {
|
||||
let deedTypeWithoutOfficeUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
deedTypeWithoutOfficeUid.office.uid = "random uuid";
|
||||
// try to create a new deed type with unknown office
|
||||
async function createDeedTypeWithUnknownOffice() {
|
||||
await DeedTypeServiceTest.create(deedType);
|
||||
await DeedTypeServiceTest.create(deedTypeWithoutOfficeUid);
|
||||
}
|
||||
await expect(createDeedTypeWithUnknownOffice).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("should create a new deed type", async () => {
|
||||
let deedTypeWithOfficeUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
deedTypeWithOfficeUid.office.uid = office1.uuid;
|
||||
const deedTypeCreated = await DeedTypeServiceTest.create(deedTypeWithOfficeUid);
|
||||
const deedTypeCreated = await DeedTypeServiceTest.create(deedType);
|
||||
|
||||
expect(deedTypeCreated.name).toEqual(deedType.name);
|
||||
expect(deedTypeCreated.description).toEqual(deedType.description);
|
||||
expect(deedTypeCreated.archived_at).toBeNull();
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office.uid);
|
||||
});
|
||||
|
||||
it("should not create a new deed type with a name already used for a given office", async () => {
|
||||
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||
deedTypeWithSameNameAndOffice.office.uid = office1.uuid;
|
||||
deedTypeWithSameNameAndOffice.office = office;
|
||||
deedTypeWithSameNameAndOffice.name = deedType.name;
|
||||
|
||||
async function createDeedTypeWithSameNameAndOffice() {
|
||||
@ -109,19 +59,18 @@ describe("test create function", () => {
|
||||
|
||||
it("should create the same deed type for a different office", async () => {
|
||||
let deedTypeDuplicatedForNewOffice: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
deedTypeDuplicatedForNewOffice.office.uid = office2.uuid;
|
||||
deedTypeDuplicatedForNewOffice.office = office_;
|
||||
|
||||
const deedTypeCreated = await DeedTypeServiceTest.create(deedTypeDuplicatedForNewOffice);
|
||||
|
||||
expect(deedTypeCreated.name).toEqual(deedType.name);
|
||||
expect(deedTypeCreated.description).toEqual(deedType.description);
|
||||
expect(deedTypeCreated.archived_at).toBeNull();
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should create the a new deed type version with a different name for a given office", async () => {
|
||||
let deedTypeWithSameDescription: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
deedTypeWithSameDescription.office.uid = office1.uuid;
|
||||
deedTypeWithSameDescription.name = deedType_.name;
|
||||
|
||||
const deedTypeCreated = await DeedTypeServiceTest.create(deedTypeWithSameDescription);
|
||||
@ -129,21 +78,21 @@ describe("test create function", () => {
|
||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeCreated.description).toEqual(deedType.description);
|
||||
expect(deedTypeCreated.archived_at).toBeNull();
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office.uid);
|
||||
});
|
||||
});
|
||||
|
||||
describe("test update function", () => {
|
||||
it("should update a deed type data", async () => {
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office1.uuid } });
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } });
|
||||
|
||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeCreated.description).toEqual(deedType.description);
|
||||
expect(deedTypeCreated.archived_at).toBeNull();
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
expect(deedTypeCreated.office_uuid).toEqual(deedType.office.uid);
|
||||
|
||||
let deedTypeWithNewDescription: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||
deedTypeWithNewDescription.office.uid = office1.uuid;
|
||||
deedTypeWithNewDescription.office = office;
|
||||
|
||||
// update the last deed type created with his the right description
|
||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedTypeWithNewDescription);
|
||||
@ -151,13 +100,13 @@ describe("test update function", () => {
|
||||
expect(deedTypeUpdated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
||||
expect(deedTypeUpdated.archived_at).toBeNull();
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(office1.uuid);
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(deedType.office.uid);
|
||||
});
|
||||
|
||||
it("should not update a deed type name with an already used name for given office", async () => {
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office1.uuid } })).uuid;
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } })).uuid;
|
||||
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||
deedTypeWithSameNameAndOffice.office.uid = office1.uuid;
|
||||
deedTypeWithSameNameAndOffice.office.uid = office.uid;
|
||||
deedTypeWithSameNameAndOffice.name = deedType.name;
|
||||
|
||||
// update the last deed type created with his the right description
|
||||
@ -168,9 +117,9 @@ describe("test update function", () => {
|
||||
});
|
||||
|
||||
it("should not update a deed type office membership if the office already have this document type", async () => {
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office1.uuid } })).uuid;
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } })).uuid;
|
||||
let deedTypeWithSameNameAndOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||
deedTypeWithSameNameAndOffice.office.uid = office1.uuid;
|
||||
deedTypeWithSameNameAndOffice.office.uid = office.uid;
|
||||
deedTypeWithSameNameAndOffice.name = deedType.name;
|
||||
|
||||
// try to duplicate deed type in a given office
|
||||
@ -181,37 +130,33 @@ describe("test update function", () => {
|
||||
});
|
||||
|
||||
it("should update a deed type office membership", async () => {
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office1.uuid } });
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office.uid } });
|
||||
|
||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeCreated.description).toEqual(deedType_.description);
|
||||
expect(deedTypeCreated.archived_at).toBeNull();
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
|
||||
let deedTypeTransferedToNewOffice: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||
deedTypeTransferedToNewOffice.office.uid = office2.uuid;
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office.uid);
|
||||
|
||||
// update the last deed type updated with a new office membership
|
||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedTypeTransferedToNewOffice);
|
||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedType_);
|
||||
|
||||
expect(deedTypeUpdated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
||||
expect(deedTypeUpdated.archived_at).toBeNull();
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(deedType_.office.uid);
|
||||
});
|
||||
|
||||
it("should archivate a deed type", async () => {
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office2.uuid } });
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office_.uid } });
|
||||
|
||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeCreated.description).toEqual(deedType_.description);
|
||||
expect(deedTypeCreated.archived_at).toBeNull();
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypeCreated.office_uuid).toEqual(deedType_.office.uid);
|
||||
|
||||
let deedTypeArchivated: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||
deedTypeArchivated.office.uid = office2.uuid;
|
||||
const currentDate = new Date(Date.now());
|
||||
deedTypeArchivated.archived_at = currentDate;
|
||||
deedTypeArchivated.archived_at = new Date(Date.now());
|
||||
|
||||
// archivate a deed type by giving a non null date for archivated_at attribute
|
||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedTypeArchivated);
|
||||
@ -219,138 +164,111 @@ describe("test update function", () => {
|
||||
expect(deedTypeUpdated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
||||
expect(deedTypeUpdated.archived_at).toEqual(currentDate);
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should unarchivate a deed type", async () => {
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office2.uuid } });
|
||||
const deedTypeCreated = await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType_.name, office_uuid: office_.uid } });
|
||||
|
||||
expect(deedTypeCreated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeCreated.description).toEqual(deedType_.description);
|
||||
expect(deedTypeCreated.archived_at).not.toBeNull();
|
||||
expect(deedTypeCreated.office_uuid).toEqual(office2.uuid);
|
||||
|
||||
let deedTypeUnarchivated: DeedType = JSON.parse(JSON.stringify(deedType_));
|
||||
deedTypeUnarchivated.office.uid = office2.uuid;
|
||||
expect(deedTypeCreated.office_uuid).toEqual(deedType_.office.uid);
|
||||
|
||||
// unarchivate a deed type by giving a null date for archivated_at attribute
|
||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedTypeUnarchivated);
|
||||
const deedTypeUpdated = await DeedTypeServiceTest.update(deedTypeCreated.uuid, deedType_);
|
||||
|
||||
expect(deedTypeUpdated.name).toEqual(deedType_.name);
|
||||
expect(deedTypeUpdated.description).toEqual(deedType_.description);
|
||||
expect(deedTypeUpdated.archived_at).toBeNull();
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypeUpdated.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should add document types to a deed type", async () => {
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office.uid } })).uuid;
|
||||
let deedTypeToUpdate: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
|
||||
deedTypeToUpdate.deed_type_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
|
||||
await DeedTypeServiceTest.update(deedTypeUid, deedTypeToUpdate);
|
||||
|
||||
const deedTypeUpdated = await prisma.deedTypes.findFirstOrThrow({
|
||||
where: {
|
||||
uuid: deedTypeUid,
|
||||
},
|
||||
include: {
|
||||
deed_type_has_document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedTypeUpdated.deed_type_has_document_types.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("should not add document types to a deed type that already has those document types ", async () => {
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office.uid } })).uuid;
|
||||
let deedTypeToUpdate: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
|
||||
deedTypeToUpdate.deed_type_has_document_types = [
|
||||
{
|
||||
document_type: documentType,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
{
|
||||
document_type: documentType_,
|
||||
deed_type: new DeedType(),
|
||||
created_at: null,
|
||||
updated_at: null,
|
||||
},
|
||||
];
|
||||
|
||||
await DeedTypeServiceTest.update(deedTypeUid, deedTypeToUpdate);
|
||||
|
||||
const deedTypeUpdated = await prisma.deedTypes.findFirstOrThrow({
|
||||
where: {
|
||||
uuid: deedTypeUid,
|
||||
},
|
||||
include: {
|
||||
deed_type_has_document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedTypeUpdated.deed_type_has_document_types.length).toEqual(2);
|
||||
});
|
||||
|
||||
it("should delete document types from a deed", async () => {
|
||||
const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office.uid } })).uuid;
|
||||
let deedTypeToUpdate: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
|
||||
// set relation between deed and document types empty
|
||||
deedTypeToUpdate.deed_type_has_document_types = [];
|
||||
|
||||
await DeedTypeServiceTest.update(deedTypeUid, deedTypeToUpdate);
|
||||
|
||||
const deedTypeUpdated = await prisma.deedTypes.findFirstOrThrow({
|
||||
where: {
|
||||
uuid: deedTypeUid,
|
||||
},
|
||||
include: {
|
||||
deed_type_has_document_types: true,
|
||||
},
|
||||
});
|
||||
expect(deedTypeUpdated.deed_type_has_document_types.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
// describe("test addDocumentTypes function", () => {
|
||||
// it("should add document types to a deed type", async () => {
|
||||
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||
// await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
|
||||
|
||||
// const deedTypes = await prisma.deedTypes.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedTypeUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_type_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedTypes.deed_type_has_document_types.length).toEqual(2);
|
||||
// });
|
||||
|
||||
// it("should not add document types to a deed type that already has those document types ", async () => {
|
||||
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||
// let deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
|
||||
// expect(deedTypeHasDocumentTypes.length).toEqual(2);
|
||||
|
||||
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
||||
// await DeedTypeServiceTest.addDocumentTypes(deedTypeUid, documentsToAdd);
|
||||
|
||||
// deedTypeHasDocumentTypes = await prisma.deedTypeHasDocumentTypes.findMany({ where: { deed_type_uuid: deedTypeUid } });
|
||||
// expect(deedTypeHasDocumentTypes.length).toEqual(2);
|
||||
// });
|
||||
// });
|
||||
// describe("test removeDocumentTypes function", () => {
|
||||
// it("should remove document types from a deed type", async () => {
|
||||
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||
// const documentsToRemove = [documentType1.uuid];
|
||||
// await DeedTypeServiceTest.removeDocumentTypes(deedTypeUid, documentsToRemove);
|
||||
|
||||
// const deedTypeWithDocumentTypeRelations = await prisma.deedTypes.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedTypeUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_type_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types.length).toEqual(1);
|
||||
// expect(deedTypeWithDocumentTypeRelations.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
||||
// });
|
||||
// it("should not remove document types from a deed type is they were not linked", async () => {
|
||||
// let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
||||
// where: { name: deedType.name, office_uuid: office1.uuid },
|
||||
// include: {
|
||||
// deed_type_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
|
||||
|
||||
// const documentsToRemove = [documentType1.uuid];
|
||||
|
||||
// // try to duplicate deed type in a given office
|
||||
// async function removeDocumentTypeNotLinkedToDeedType() {
|
||||
// await DeedTypeServiceTest.removeDocumentTypes(deedTypeWithOneDocumentType.uuid, documentsToRemove);
|
||||
// }
|
||||
// await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
||||
// });
|
||||
// });
|
||||
// describe("test removeDocumentType function", () => {
|
||||
// it("should remove only one document type from a deed type", async () => {
|
||||
// let deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
||||
// where: { name: deedType.name, office_uuid: office1.uuid },
|
||||
// include: {
|
||||
// deed_type_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(1);
|
||||
|
||||
// const documentToRemove = documentType2.uuid;
|
||||
// await DeedTypeServiceTest.removeDocumentType(deedTypeWithOneDocumentType.uuid, documentToRemove);
|
||||
|
||||
// deedTypeWithOneDocumentType = await prisma.deedTypes.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedTypeWithOneDocumentType.uuid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_type_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedTypeWithOneDocumentType.deed_type_has_document_types.length).toEqual(0);
|
||||
// });
|
||||
// });
|
||||
// describe("test addDocumentType function", () => {
|
||||
// it("should add only one document type to a deed type", async () => {
|
||||
// const deedTypeUid = (await prisma.deedTypes.findFirstOrThrow({ where: { name: deedType.name, office_uuid: office1.uuid } })).uuid;
|
||||
// const documentToAdd = documentType1.uuid;
|
||||
// await DeedTypeServiceTest.addDocumentType(deedTypeUid, documentToAdd);
|
||||
|
||||
// const deedTypes = await prisma.deedTypes.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedTypeUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_type_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedTypes.deed_type_has_document_types.length).toEqual(1);
|
||||
// expect(deedTypes.deed_type_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe("test get function", () => {
|
||||
it("should return an array of DeedTypes", async () => {
|
||||
const deedTypes = await DeedTypeServiceTest.get({ orderBy: [{ name: "asc" }, { created_at: "asc" }] });
|
||||
@ -363,21 +281,21 @@ describe("test get function", () => {
|
||||
expect(deedTypes[0]?.name).toEqual(deedType_.name);
|
||||
expect(deedTypes[0]?.description).toEqual(deedType_.description);
|
||||
expect(deedTypes[0]?.archived_at).toBeNull();
|
||||
expect(deedTypes[0]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypes[0]?.office_uuid).toEqual(office_.uid);
|
||||
|
||||
expect(deedTypes[1]?.name).toEqual(deedType.name);
|
||||
expect(deedTypes[1]?.description).toEqual(deedType.description);
|
||||
expect(deedTypes[1]?.archived_at).toBeNull();
|
||||
expect(deedTypes[1]?.office_uuid).toEqual(office1.uuid);
|
||||
expect(deedTypes[1]?.office_uuid).toEqual(office.uid);
|
||||
|
||||
expect(deedTypes[2]?.name).toEqual(deedType.name);
|
||||
expect(deedTypes[2]?.description).toEqual(deedType.description);
|
||||
expect(deedTypes[2]?.archived_at).toBeNull();
|
||||
expect(deedTypes[2]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypes[2]?.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should return an array of DeedTypes per offices", async () => {
|
||||
const deedTypesForFirstOffice = await DeedTypeServiceTest.get({ where: { office: office1 }, orderBy: { name: "asc" } });
|
||||
const deedTypesForFirstOffice = await DeedTypeServiceTest.get({ where: { office: {uuid: office.uid} }, orderBy: { name: "asc" } });
|
||||
|
||||
expect(deedTypesForFirstOffice.length).toEqual(1);
|
||||
|
||||
@ -385,9 +303,9 @@ describe("test get function", () => {
|
||||
expect(deedTypesForFirstOffice[0]?.name).toEqual(deedType.name);
|
||||
expect(deedTypesForFirstOffice[0]?.description).toEqual(deedType.description);
|
||||
expect(deedTypesForFirstOffice[0]?.archived_at).toBeNull();
|
||||
expect(deedTypesForFirstOffice[0]?.office_uuid).toEqual(office1.uuid);
|
||||
expect(deedTypesForFirstOffice[0]?.office_uuid).toEqual(office.uid);
|
||||
|
||||
const deedTypesForSecondOffice = await DeedTypeServiceTest.get({ where: { office: office2 }, orderBy: { name: "asc" } });
|
||||
const deedTypesForSecondOffice = await DeedTypeServiceTest.get({ where: { office: {uuid: office_.uid} }, orderBy: { name: "asc" } });
|
||||
|
||||
expect(deedTypesForSecondOffice.length).toEqual(2);
|
||||
|
||||
@ -395,11 +313,11 @@ describe("test get function", () => {
|
||||
expect(deedTypesForSecondOffice[0]?.name).toEqual(deedType_.name);
|
||||
expect(deedTypesForSecondOffice[0]?.description).toEqual(deedType_.description);
|
||||
expect(deedTypesForSecondOffice[0]?.archived_at).toBeNull();
|
||||
expect(deedTypesForSecondOffice[0]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypesForSecondOffice[0]?.office_uuid).toEqual(office_.uid);
|
||||
|
||||
expect(deedTypesForSecondOffice[1]?.name).toEqual(deedType.name);
|
||||
expect(deedTypesForSecondOffice[1]?.description).toEqual(deedType.description);
|
||||
expect(deedTypesForSecondOffice[1]?.archived_at).toBeNull();
|
||||
expect(deedTypesForSecondOffice[1]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(deedTypesForSecondOffice[1]?.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
});
|
||||
|
@ -2,48 +2,19 @@ import "module-alias/register";
|
||||
import "reflect-metadata";
|
||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
import { PrismaClient, Offices } from "prisma/prisma-client";
|
||||
import { documentType, documentType_, office, office_ } from "./MockedData";
|
||||
import { PrismaClient } from "prisma/prisma-client";
|
||||
import { documentType, documentType_, office, office_ } from "@Test/config/MockedData";
|
||||
import DocumentTypesRepository from "@Repositories/DocumentTypesRepository";
|
||||
import Container from "typedi";
|
||||
import { initOffice } from "@Test/config/Init";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const DocumentTypesServiceTest = new DocumentTypesService(Container.get(DocumentTypesRepository));
|
||||
|
||||
let office1: Offices;
|
||||
let office2: Offices;
|
||||
|
||||
beforeAll(async () => {
|
||||
office1 = await prisma.offices.create({
|
||||
data: {
|
||||
idNot: office.idNot,
|
||||
name: office.name,
|
||||
crpcen: office.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: office.address.address,
|
||||
zip_code: office.address.zip_code,
|
||||
city: office.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
office2 = await prisma.offices.create({
|
||||
data: {
|
||||
idNot: office_.idNot,
|
||||
name: office_.name,
|
||||
crpcen: office_.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: office_.address.address,
|
||||
zip_code: office_.address.zip_code,
|
||||
city: office_.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
office.uid = (await initOffice(office)).uuid;
|
||||
office_.uid = (await initOffice(office_)).uuid;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@ -55,28 +26,30 @@ afterAll(async () => {
|
||||
|
||||
describe("test create function", () => {
|
||||
it("should not create a new document type if office is unknown", async () => {
|
||||
let documentTypeWithoutOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType));
|
||||
documentTypeWithoutOfficeUid.office.uid = "random uuid";
|
||||
// try to create a new document type with unknown office
|
||||
async function createDocumentTypeWithUnknownOffice() {
|
||||
await DocumentTypesServiceTest.create(documentType);
|
||||
await DocumentTypesServiceTest.create(documentTypeWithoutOfficeUid);
|
||||
}
|
||||
await expect(createDocumentTypeWithUnknownOffice).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("should create a new document type", async () => {
|
||||
let documentTypeWithOfficeUid: DocumentType = JSON.parse(JSON.stringify(documentType));
|
||||
documentTypeWithOfficeUid.office.uid = office1.uuid;
|
||||
documentTypeWithOfficeUid.office.uid = office.uid;
|
||||
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithOfficeUid);
|
||||
|
||||
expect(documentTypeCreated.name).toEqual(documentType.name);
|
||||
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypeCreated.archived_at).toBeNull();
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
|
||||
});
|
||||
|
||||
it("should not create a new document type with a name already used for a given office", async () => {
|
||||
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||
documentTypeWithSameNameAndOffice.office.uid = office1.uuid;
|
||||
documentTypeWithSameNameAndOffice.office.uid = office.uid;
|
||||
documentTypeWithSameNameAndOffice.name = documentType.name;
|
||||
|
||||
async function createDocumentTypeWithSameNameAndOffice() {
|
||||
@ -87,7 +60,7 @@ describe("test create function", () => {
|
||||
|
||||
it("should create the same document type for a different office", async () => {
|
||||
let documentTypeDuplicatedForNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType));
|
||||
documentTypeDuplicatedForNewOffice.office.uid = office2.uuid;
|
||||
documentTypeDuplicatedForNewOffice.office.uid = office_.uid;
|
||||
|
||||
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeDuplicatedForNewOffice);
|
||||
|
||||
@ -95,12 +68,12 @@ describe("test create function", () => {
|
||||
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypeCreated.archived_at).toBeNull();
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should create a new document type version with a different name for a given office", async () => {
|
||||
let documentTypeWithSameDescription: DocumentType = JSON.parse(JSON.stringify(documentType));
|
||||
documentTypeWithSameDescription.office.uid = office1.uuid;
|
||||
documentTypeWithSameDescription.office.uid = office.uid;
|
||||
documentTypeWithSameDescription.name = documentType_.name;
|
||||
|
||||
const documentTypeCreated = await DocumentTypesServiceTest.create(documentTypeWithSameDescription);
|
||||
@ -109,23 +82,23 @@ describe("test create function", () => {
|
||||
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypeCreated.archived_at).toBeNull();
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
|
||||
});
|
||||
});
|
||||
|
||||
describe("test update function", () => {
|
||||
it("should update a document type", async () => {
|
||||
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
|
||||
where: { name: documentType_.name, office_uuid: office1.uuid },
|
||||
where: { name: documentType_.name, office_uuid: office.uid },
|
||||
});
|
||||
expect(documentTypeCreated.name).toEqual(documentType_.name);
|
||||
expect(documentTypeCreated.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypeCreated.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypeCreated.archived_at).toBeNull();
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
|
||||
|
||||
let documentTypeWithNewDescription: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||
documentTypeWithNewDescription.office.uid = office1.uuid;
|
||||
documentTypeWithNewDescription.office.uid = office.uid;
|
||||
|
||||
// update the last document type created with his the right descriptions
|
||||
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uuid, documentTypeWithNewDescription);
|
||||
@ -133,15 +106,15 @@ describe("test update function", () => {
|
||||
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypeUpdated.archived_at).toBeNull();
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office1.uuid);
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office.uid);
|
||||
});
|
||||
|
||||
it("should not update a document type name with an already used name for given office", async () => {
|
||||
const documentTypeUid = (
|
||||
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uuid: office1.uuid } })
|
||||
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uuid: office.uid } })
|
||||
).uuid;
|
||||
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||
documentTypeWithSameNameAndOffice.office.uid = office1.uuid;
|
||||
documentTypeWithSameNameAndOffice.office.uid = office.uid;
|
||||
documentTypeWithSameNameAndOffice.name = documentType.name;
|
||||
|
||||
// update the last document type created with his the right description
|
||||
@ -153,10 +126,10 @@ describe("test update function", () => {
|
||||
|
||||
it("should not update a document type office membership if the office already has this document type", async () => {
|
||||
const documentTypeUid = (
|
||||
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uuid: office1.uuid } })
|
||||
await prisma.documentTypes.findFirstOrThrow({ where: { name: documentType_.name, office_uuid: office.uid } })
|
||||
).uuid;
|
||||
let documentTypeWithSameNameAndOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||
documentTypeWithSameNameAndOffice.office.uid = office1.uuid;
|
||||
documentTypeWithSameNameAndOffice.office.uid = office.uid;
|
||||
documentTypeWithSameNameAndOffice.name = documentType.name;
|
||||
|
||||
// try to duplicate document type in a given office
|
||||
@ -168,17 +141,17 @@ describe("test update function", () => {
|
||||
|
||||
it("should update a document type office membership", async () => {
|
||||
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
|
||||
where: { name: documentType_.name, office_uuid: office1.uuid },
|
||||
where: { name: documentType_.name, office_uuid: office.uid },
|
||||
});
|
||||
|
||||
expect(documentTypeCreated.name).toEqual(documentType_.name);
|
||||
expect(documentTypeCreated.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypeCreated.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypeCreated.archived_at).toBeNull();
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office1.uuid);
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office.uid);
|
||||
|
||||
let documentTypeTransferedToNewOffice: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||
documentTypeTransferedToNewOffice.office.uid = office2.uuid;
|
||||
documentTypeTransferedToNewOffice.office.uid = office_.uid;
|
||||
|
||||
// update the last document type updated with a new office membership
|
||||
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uuid, documentTypeTransferedToNewOffice);
|
||||
@ -187,22 +160,22 @@ describe("test update function", () => {
|
||||
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypeUpdated.archived_at).toBeNull();
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should archivate a document type", async () => {
|
||||
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
|
||||
where: { name: documentType_.name, office_uuid: office2.uuid },
|
||||
where: { name: documentType_.name, office_uuid: office_.uid },
|
||||
});
|
||||
|
||||
expect(documentTypeCreated.name).toEqual(documentType_.name);
|
||||
expect(documentTypeCreated.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypeCreated.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypeCreated.archived_at).toBeNull();
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office_.uid);
|
||||
|
||||
let documentTypeArchivated: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||
documentTypeArchivated.office.uid = office2.uuid;
|
||||
documentTypeArchivated.office.uid = office_.uid;
|
||||
const currentDate = new Date(Date.now());
|
||||
documentTypeArchivated.archived_at = currentDate;
|
||||
// archivate a document type by giving a non null date for archivated_at attribute
|
||||
@ -211,22 +184,22 @@ describe("test update function", () => {
|
||||
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypeUpdated.archived_at).toEqual(currentDate);
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should unarchivate a document type", async () => {
|
||||
const documentTypeCreated = await prisma.documentTypes.findFirstOrThrow({
|
||||
where: { name: documentType_.name, office_uuid: office2.uuid },
|
||||
where: { name: documentType_.name, office_uuid: office_.uid },
|
||||
});
|
||||
|
||||
expect(documentTypeCreated.name).toEqual(documentType_.name);
|
||||
expect(documentTypeCreated.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypeCreated.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypeCreated.archived_at).not.toBeNull();
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypeCreated.office_uuid).toEqual(office_.uid);
|
||||
|
||||
let documentTypeUnarchivated: DocumentType = JSON.parse(JSON.stringify(documentType_));
|
||||
documentTypeUnarchivated.office.uid = office2.uuid;
|
||||
documentTypeUnarchivated.office.uid = office_.uid;
|
||||
|
||||
// unarchivate a document type by giving a null date for archivated_at attribute
|
||||
const documentTypeUpdated = await DocumentTypesServiceTest.update(documentTypeCreated.uuid, documentTypeUnarchivated);
|
||||
@ -235,7 +208,7 @@ describe("test update function", () => {
|
||||
expect(documentTypeUpdated.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypeUpdated.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypeUpdated.archived_at).toBeNull();
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypeUpdated.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
});
|
||||
|
||||
@ -252,23 +225,23 @@ describe("test get function", () => {
|
||||
expect(documentTypes[0]?.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypes[0]?.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypes[0]?.archived_at).toBeNull();
|
||||
expect(documentTypes[0]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypes[0]?.office_uuid).toEqual(office_.uid);
|
||||
|
||||
expect(documentTypes[1]?.name).toEqual(documentType.name);
|
||||
expect(documentTypes[1]?.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypes[1]?.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypes[1]?.archived_at).toBeNull();
|
||||
expect(documentTypes[1]?.office_uuid).toEqual(office1.uuid);
|
||||
expect(documentTypes[1]?.office_uuid).toEqual(office.uid);
|
||||
|
||||
expect(documentTypes[2]?.name).toEqual(documentType.name);
|
||||
expect(documentTypes[2]?.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypes[2]?.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypes[2]?.archived_at).toBeNull();
|
||||
expect(documentTypes[2]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypes[2]?.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
|
||||
it("should return an array of DocumentTypes per offices", async () => {
|
||||
const documentTypesForFirstOffice = await DocumentTypesServiceTest.get({ where: { office: office1 }, orderBy: { name: "asc" } });
|
||||
const documentTypesForFirstOffice = await DocumentTypesServiceTest.get({ where: { office: {uuid : office.uid }}, orderBy: { name: "asc" } });
|
||||
|
||||
expect(documentTypesForFirstOffice.length).toEqual(1);
|
||||
|
||||
@ -277,9 +250,9 @@ describe("test get function", () => {
|
||||
expect(documentTypesForFirstOffice[0]?.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypesForFirstOffice[0]?.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypesForFirstOffice[0]?.archived_at).toBeNull();
|
||||
expect(documentTypesForFirstOffice[0]?.office_uuid).toEqual(office1.uuid);
|
||||
expect(documentTypesForFirstOffice[0]?.office_uuid).toEqual(office.uid);
|
||||
|
||||
const documentTypesForSecondOffice = await DocumentTypesServiceTest.get({ where: { office: office2 }, orderBy: { name: "asc" } });
|
||||
const documentTypesForSecondOffice = await DocumentTypesServiceTest.get({ where: { office: {uuid : office_.uid }}, orderBy: { name: "asc" } });
|
||||
|
||||
expect(documentTypesForSecondOffice.length).toEqual(2);
|
||||
|
||||
@ -288,12 +261,12 @@ describe("test get function", () => {
|
||||
expect(documentTypesForSecondOffice[0]?.public_description).toEqual(documentType_.public_description);
|
||||
expect(documentTypesForSecondOffice[0]?.private_description).toEqual(documentType_.private_description);
|
||||
expect(documentTypesForSecondOffice[0]?.archived_at).toBeNull();
|
||||
expect(documentTypesForSecondOffice[0]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypesForSecondOffice[0]?.office_uuid).toEqual(office_.uid);
|
||||
|
||||
expect(documentTypesForSecondOffice[1]?.name).toEqual(documentType.name);
|
||||
expect(documentTypesForSecondOffice[1]?.public_description).toEqual(documentType.public_description);
|
||||
expect(documentTypesForSecondOffice[1]?.private_description).toEqual(documentType.private_description);
|
||||
expect(documentTypesForSecondOffice[1]?.archived_at).toBeNull();
|
||||
expect(documentTypesForSecondOffice[1]?.office_uuid).toEqual(office2.uuid);
|
||||
expect(documentTypesForSecondOffice[1]?.office_uuid).toEqual(office_.uid);
|
||||
});
|
||||
});
|
||||
|
@ -1,273 +1,288 @@
|
||||
import "module-alias/register";
|
||||
import "reflect-metadata";
|
||||
import { PrismaClient, Offices, DocumentTypes, DeedTypes, DeedTypeHasDocumentTypes } from "prisma/prisma-client";
|
||||
import { deedType, documentType, office } from "./MockedData";
|
||||
// import Container from "typedi";
|
||||
// import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||
// import OfficeFoldersHasStakeholderRepository from "@Repositories/OfficeFoldersHasStakeholderRepository";
|
||||
// import OfficeFoldersHasCustomerRepository from "@Repositories/OfficeFoldersHasCustomerRepository";
|
||||
// import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||
// import OfficeFolderService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||
// import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import { OfficeFolderHasCustomers, OfficeFolderHasStakeholders, PrismaClient } from "prisma/prisma-client";
|
||||
import {
|
||||
customer,
|
||||
customer_,
|
||||
deedType,
|
||||
documentType,
|
||||
documentType_,
|
||||
office,
|
||||
officeFolder,
|
||||
officeFolder_,
|
||||
user,
|
||||
user_,
|
||||
} from "@Test/config/MockedData";
|
||||
import Container from "typedi";
|
||||
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||
import OfficeFolderService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||
import { initCustomers, initDeedType, initDocumentType, initOffice, initUsers } from "@Test/config/Init";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesService";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
// const OfficeFolderServiceTest = new OfficeFolderService(
|
||||
// Container.get(OfficeFoldersRepository),
|
||||
// Container.get(OfficeFoldersHasStakeholderRepository),
|
||||
// Container.get(OfficeFoldersHasCustomerRepository),
|
||||
// Container.get(CustomersService),
|
||||
// Container.get(DocumentsRepository),
|
||||
// );
|
||||
|
||||
let office1: Offices;
|
||||
|
||||
let documentType1: DocumentTypes;
|
||||
//let documentType2: DocumentTypes;
|
||||
|
||||
let deedType1: DeedTypes;
|
||||
|
||||
let deedType1HasDocumentType1: DeedTypeHasDocumentTypes;
|
||||
const OfficeFolderServiceTest = new OfficeFolderService(Container.get(OfficeFoldersRepository), Container.get(DeedTypesService));
|
||||
|
||||
beforeAll(async () => {
|
||||
office1 = await prisma.offices.create({
|
||||
data: {
|
||||
idNot: office.idNot,
|
||||
name: office.name,
|
||||
crpcen: office.crpcen,
|
||||
address: {
|
||||
create: {
|
||||
address: office.address.address,
|
||||
zip_code: office.address.zip_code,
|
||||
city: office.address.city,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
documentType1 = await prisma.documentTypes.create({
|
||||
data: {
|
||||
name: documentType.name,
|
||||
public_description: documentType.public_description,
|
||||
private_description: documentType.private_description,
|
||||
archived_at: null,
|
||||
office_uuid: office1.uuid,
|
||||
},
|
||||
});
|
||||
|
||||
// documentType2 = await prisma.documentTypes.create({
|
||||
// data: {
|
||||
// name: documentType_.name,
|
||||
// public_description: documentType_.public_description,
|
||||
// private_description: documentType_.private_description,
|
||||
// archived_at: null,
|
||||
// office_uuid: office1.uuid,
|
||||
// },
|
||||
// });
|
||||
|
||||
deedType1 = await prisma.deedTypes.create({
|
||||
data: {
|
||||
name: deedType.name,
|
||||
description: deedType.description,
|
||||
archived_at: null,
|
||||
office_uuid: office1.uuid,
|
||||
},
|
||||
});
|
||||
|
||||
deedType1HasDocumentType1 = await prisma.deedTypeHasDocumentTypes.create({
|
||||
data: {
|
||||
deed_type_uuid: deedType1.uuid,
|
||||
document_type_uuid: documentType1.uuid,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.deedTypes.update({
|
||||
where: { uuid: deedType1.uuid },
|
||||
data: {
|
||||
deed_type_has_document_types: {
|
||||
connect: {
|
||||
uuid: deedType1HasDocumentType1.uuid,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
office.uid = (await initOffice(office)).uuid;
|
||||
documentType.uid = (await initDocumentType(documentType, office)).uuid;
|
||||
documentType_.uid = (await initDocumentType(documentType_, office)).uuid;
|
||||
deedType.uid = (await initDeedType(deedType, office, [documentType.uid])).uuid;
|
||||
user.uid = (await initUsers(user)).uuid;
|
||||
user_.uid = (await initUsers(user_)).uuid;
|
||||
customer.uid = (await initCustomers(customer)).uuid;
|
||||
customer_.uid = (await initCustomers(customer_)).uuid;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
/*
|
||||
* Clean database after all tests execution.
|
||||
* Due to cascade deletion, if addresses are deleted, all items following tables are dropped: contacts, customers, offices
|
||||
*/
|
||||
const deleteDeedTypes = prisma.deedTypes.deleteMany();
|
||||
const deleteOffices = prisma.offices.deleteMany();
|
||||
await prisma.$transaction([deleteDeedTypes, deleteOffices]);
|
||||
const deleteAddresses = prisma.addresses.deleteMany();
|
||||
await prisma.$transaction([deleteDeedTypes, deleteAddresses]);
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
|
||||
describe("test create function", () => {
|
||||
it("should not create a new office folder if deed type is unknown", async () => {
|
||||
let officeFolderWithoutDeedTypeUid: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
||||
officeFolderWithoutDeedTypeUid.deed.deed_type.uid = "random uuid";
|
||||
// try to create a new deed with unknown deed type
|
||||
// async function createDeedWithUnknownDeedType() {
|
||||
// await OfficeFolderServiceTest.create(officeFolder, deedType);
|
||||
// }
|
||||
// await expect(createDeedWithUnknownDeedType).rejects.toThrow("deed type not found");
|
||||
async function createOfficeFolderWithUnknownDeedType() {
|
||||
await OfficeFolderServiceTest.create(officeFolderWithoutDeedTypeUid);
|
||||
}
|
||||
await expect(createOfficeFolderWithUnknownDeedType).rejects.toThrow();
|
||||
});
|
||||
|
||||
// it("should create a new office folder based on existing deed type", async () => {
|
||||
// let deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
// deedTypeWithUid.uid = deedType1.uuid;
|
||||
// const officeFolderCreated = await OfficeFolderServiceTest.create(officeFolder, deedTypeWithUid);
|
||||
it("should create a new office folder based on existing deed type", async () => {
|
||||
const officeFolderCreated = await OfficeFolderServiceTest.create(officeFolder);
|
||||
|
||||
// expect(officeFolderCreated.office_uuid).toEqual(office1.uuid);
|
||||
// expect(officeFolderCreated.deed_uuid.).toEqual(office1.uuid);
|
||||
// });
|
||||
const deedCreated = await prisma.deeds.findUniqueOrThrow({ where: { uuid: officeFolderCreated.deed_uuid } });
|
||||
|
||||
// it("should have by default the same document types as its deed type ", async () => {
|
||||
// const deedWithDocumentTypes = await prisma.deeds.findFirstOrThrow({ include: { deed_has_document_types: true } });
|
||||
// expect(deedWithDocumentTypes.deed_has_document_types.length).toEqual(1);
|
||||
// expect(deedWithDocumentTypes.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||
// });
|
||||
expect(officeFolderCreated.name).toEqual(officeFolder.name);
|
||||
expect(officeFolderCreated.folder_number).toEqual(officeFolder.folder_number);
|
||||
expect(officeFolderCreated.description).toEqual(officeFolder.description);
|
||||
expect(officeFolderCreated.archived_description).toEqual(null);
|
||||
expect(officeFolderCreated.status).toEqual("LIVE");
|
||||
expect(officeFolderCreated.office_uuid).toEqual(officeFolder.office.uid);
|
||||
expect(deedCreated.deed_type_uuid).toEqual(officeFolder.deed.deed_type.uid);
|
||||
});
|
||||
|
||||
// it("should create a the same deed based on existing deed type", async () => {
|
||||
// let deedTypeWithUid: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
// deedTypeWithUid.uid = deedType1.uuid;
|
||||
// const deedCreated = await OfficeFolderServiceTest.create(deedTypeWithUid);
|
||||
it("should contains stakeholders", async () => {
|
||||
const officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_stakeholder: true },
|
||||
});
|
||||
const stakeholderRelation = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uuid_user_stakeholder_uuid: {
|
||||
user_stakeholder_uuid: user.uid!,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
},
|
||||
},
|
||||
});
|
||||
const stakeholderRelation_ = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uuid_user_stakeholder_uuid: {
|
||||
user_stakeholder_uuid: user_.uid!,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder.length).toEqual(2);
|
||||
const stakeholder: OfficeFolderHasStakeholders = {
|
||||
uuid: stakeholderRelation.uuid,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
user_stakeholder_uuid: user.uid!,
|
||||
created_at: officeFolderCreated.created_at,
|
||||
updated_at: officeFolderCreated.updated_at,
|
||||
};
|
||||
const stakeholder_: OfficeFolderHasStakeholders = {
|
||||
uuid: stakeholderRelation_.uuid,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
user_stakeholder_uuid: user_.uid!,
|
||||
created_at: officeFolderCreated.created_at,
|
||||
updated_at: officeFolderCreated.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder).toEqual(expect.arrayContaining([stakeholder, stakeholder_]));
|
||||
});
|
||||
|
||||
// expect(deedCreated.deed_type_uuid).toEqual(deedType1.uuid);
|
||||
// });
|
||||
it("should not create a new office folder with folder number already created", async () => {
|
||||
let officeFolderWithSameFolderNumber: OfficeFolder = JSON.parse(JSON.stringify(officeFolder_));
|
||||
officeFolderWithSameFolderNumber.folder_number = officeFolder.folder_number;
|
||||
// try to create a new deed with unknown deed type
|
||||
async function createOfficeFolderWithSameFolderNumber() {
|
||||
await OfficeFolderServiceTest.create(officeFolderWithSameFolderNumber);
|
||||
}
|
||||
await expect(createOfficeFolderWithSameFolderNumber).rejects.toThrow();
|
||||
});
|
||||
|
||||
// it("should not create a new deed based on archivated deed type", async () => {
|
||||
// let deedTypeArchivated: DeedType = JSON.parse(JSON.stringify(deedType));
|
||||
// deedTypeArchivated.uid = deedType1.uuid;
|
||||
|
||||
// await prisma.deedTypes.update({
|
||||
// where: { uuid: deedType1.uuid },
|
||||
// data: {
|
||||
// archived_at: new Date(Date.now()),
|
||||
// },
|
||||
// });
|
||||
|
||||
// // try to create a new deed with archivated deed type
|
||||
// async function createDeedWithArchivatedDeedType() {
|
||||
// await OfficeFolderServiceTest.create(deedTypeArchivated);
|
||||
// }
|
||||
// await expect(createDeedWithArchivatedDeedType).rejects.toThrow("deed type is archived");
|
||||
// });
|
||||
it("should not create a new office folder if deed type is archived", async () => {
|
||||
await prisma.deedTypes.update({ where: { uuid: deedType.uid }, data: { archived_at: new Date(Date.now()) } });
|
||||
// try to create a new deed with archivated deed type
|
||||
async function createDeedWithArchivatedDeedType() {
|
||||
await OfficeFolderServiceTest.create(officeFolder);
|
||||
}
|
||||
await expect(createDeedWithArchivatedDeedType).rejects.toThrow("deed type is archived");
|
||||
});
|
||||
});
|
||||
|
||||
// describe("test addDocumentTypes function", () => {
|
||||
// it("should add document types to a deed", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||
// await OfficeFolderServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||
describe("test update function", () => {
|
||||
it("should add customers", async () => {
|
||||
let officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
});
|
||||
|
||||
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deed.deed_has_document_types.length).toEqual(2);
|
||||
// });
|
||||
expect(officeFolderCreated.office_folder_has_customers).toEqual([]);
|
||||
// mocked data contains the customers
|
||||
await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolder);
|
||||
|
||||
// it("should not add document types to a deed type that already has those document types ", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// let deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||
const customerRelation = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uuid_customer_uuid: {
|
||||
customer_uuid: customer.uid!,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
},
|
||||
},
|
||||
});
|
||||
const customerRelation_ = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uuid_customer_uuid: {
|
||||
customer_uuid: customer_.uid!,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// const documentsToAdd = [documentType1.uuid, documentType2.uuid];
|
||||
// //we expect deedTypeHasDocumentTypes service to skip duplicates without throwing error
|
||||
// await OfficeFolderServiceTest.addDocumentTypes(deedUid, documentsToAdd);
|
||||
officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
});
|
||||
|
||||
// deedHasDocumentTypes = await prisma.deedHasDocumentTypes.findMany({ where: { deed_uuid: deedUid } });
|
||||
// expect(deedHasDocumentTypes.length).toEqual(2);
|
||||
// });
|
||||
// });
|
||||
// describe("test removeDocumentTypes function", () => {
|
||||
// it("should remove document types from a deed type", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// const documentsToRemove = [documentType1.uuid];
|
||||
// await OfficeFolderServiceTest.removeDocumentTypes(deedUid, documentsToRemove);
|
||||
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(2);
|
||||
const officeFolderHasCustomer: OfficeFolderHasCustomers = {
|
||||
uuid: customerRelation.uuid,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
customer_uuid: customer.uid!,
|
||||
created_at: customerRelation.created_at,
|
||||
updated_at: customerRelation.updated_at,
|
||||
};
|
||||
const officeFolderHasCustomer_: OfficeFolderHasCustomers = {
|
||||
uuid: customerRelation_.uuid,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
customer_uuid: customer_.uid!,
|
||||
created_at: customerRelation_.created_at,
|
||||
updated_at: customerRelation_.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_customers).toEqual(
|
||||
expect.arrayContaining([officeFolderHasCustomer, officeFolderHasCustomer_]),
|
||||
);
|
||||
});
|
||||
|
||||
// const deedWithDocumentTypeRelations = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithDocumentTypeRelations.deed_has_document_types.length).toEqual(1);
|
||||
// expect(deedWithDocumentTypeRelations.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType2.uuid);
|
||||
// });
|
||||
// it("should not remove document types from a deed type is they were not linked", async () => {
|
||||
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||
// where: { deed_type_uuid: deedType1.uuid },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||
it("should remove customers", async () => {
|
||||
let officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
});
|
||||
|
||||
// const documentsToRemove = [documentType1.uuid];
|
||||
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(2);
|
||||
|
||||
// async function removeDocumentTypeNotLinkedToDeedType() {
|
||||
// await OfficeFolderServiceTest.removeDocumentTypes(deedWithOneDocumentType.uuid, documentsToRemove);
|
||||
// }
|
||||
// await expect(removeDocumentTypeNotLinkedToDeedType).rejects.toThrow();
|
||||
// });
|
||||
// });
|
||||
// describe("test removeDocumentType function", () => {
|
||||
// it("should remove only one document type from a deed type", async () => {
|
||||
// let deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||
// where: { deed_type_uuid: deedType1.uuid },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(1);
|
||||
let officeFolderWithLessCustomers: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
||||
officeFolderWithLessCustomers.office_folder_has_customers!.pop();
|
||||
// mocked data contains the customers
|
||||
await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderWithLessCustomers);
|
||||
|
||||
// const documentToRemove = documentType2.uuid;
|
||||
// await OfficeFolderServiceTest.removeDocumentType(deedWithOneDocumentType.uuid, documentToRemove);
|
||||
const customerRelation = await prisma.officeFolderHasCustomers.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uuid_customer_uuid: {
|
||||
customer_uuid: customer.uid!,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// deedWithOneDocumentType = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedWithOneDocumentType.uuid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deedWithOneDocumentType.deed_has_document_types.length).toEqual(0);
|
||||
// });
|
||||
// });
|
||||
// describe("test addDocumentType function", () => {
|
||||
// it("should add only one document type to a deed type", async () => {
|
||||
// const deedUid = (await prisma.deeds.findFirstOrThrow({ where: { deed_type_uuid: deedType1.uuid } })).uuid;
|
||||
// const documentToAdd = documentType1.uuid;
|
||||
// await OfficeFolderServiceTest.addDocumentType(deedUid, documentToAdd);
|
||||
officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_customers: true },
|
||||
});
|
||||
|
||||
// const deed = await prisma.deeds.findFirstOrThrow({
|
||||
// where: {
|
||||
// uuid: deedUid,
|
||||
// },
|
||||
// include: {
|
||||
// deed_has_document_types: true,
|
||||
// },
|
||||
// });
|
||||
// expect(deed.deed_has_document_types.length).toEqual(1);
|
||||
// expect(deed.deed_has_document_types[0]?.document_type_uuid).toEqual(documentType1.uuid);
|
||||
// });
|
||||
// });
|
||||
expect(officeFolderCreated.office_folder_has_customers.length).toEqual(1);
|
||||
const officeFolderHasCustomer: OfficeFolderHasCustomers = {
|
||||
uuid: customerRelation.uuid,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
customer_uuid: customer.uid!,
|
||||
created_at: customerRelation.created_at,
|
||||
updated_at: customerRelation.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_customers).toEqual([officeFolderHasCustomer]);
|
||||
});
|
||||
it("should remove stakeholders", async () => {
|
||||
let officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_stakeholder: true },
|
||||
});
|
||||
|
||||
// describe("test get function", () => {
|
||||
// it("should return an array of Deeds", async () => {
|
||||
// const deeds = await OfficeFolderServiceTest.get({});
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder.length).toEqual(2);
|
||||
|
||||
// // verify result typing
|
||||
// expect(deeds).toBeInstanceOf(Array<Deed>);
|
||||
// expect(deeds.length).toEqual(2);
|
||||
let officeFolderWithLessStakeholders: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
||||
officeFolderWithLessStakeholders.office_folder_has_stakeholder!.pop();
|
||||
// mocked data contains the customers
|
||||
await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderWithLessStakeholders);
|
||||
|
||||
// // verify result content
|
||||
// expect(deeds[0]?.deed_type_uuid).toEqual(deedType1.uuid);
|
||||
// expect(deeds[1]?.deed_type_uuid).toEqual(deedType1.uuid);
|
||||
// });
|
||||
// });
|
||||
const stakeholderRelation = await prisma.officeFolderHasStakeholders.findUniqueOrThrow({
|
||||
where: {
|
||||
office_folder_uuid_user_stakeholder_uuid: {
|
||||
user_stakeholder_uuid: user.uid!,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({
|
||||
include: { office_folder_has_stakeholder: true },
|
||||
});
|
||||
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder.length).toEqual(1);
|
||||
const officeFolderHasStakeholder: OfficeFolderHasStakeholders = {
|
||||
uuid: stakeholderRelation.uuid,
|
||||
office_folder_uuid: officeFolderCreated.uuid,
|
||||
user_stakeholder_uuid: user.uid!,
|
||||
created_at: stakeholderRelation.created_at,
|
||||
updated_at: stakeholderRelation.updated_at,
|
||||
};
|
||||
expect(officeFolderCreated.office_folder_has_stakeholder).toEqual([officeFolderHasStakeholder]);
|
||||
});
|
||||
it("should archivate an office folder", async () => {
|
||||
const officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({});
|
||||
let officeFolderArchived: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
||||
// mocked data for this office folder is "ARCHIVATED" by default
|
||||
officeFolderArchived.archived_description = "folder complete";
|
||||
|
||||
const officeFolderUpdated = await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderArchived);
|
||||
|
||||
expect(officeFolderUpdated.archived_description).toEqual(officeFolderArchived.archived_description);
|
||||
expect(officeFolderUpdated.status).toEqual("ARCHIVED");
|
||||
});
|
||||
it("should unarchivate an office folder", async () => {
|
||||
const officeFolderCreated = await prisma.officeFolders.findFirstOrThrow({});
|
||||
|
||||
expect(officeFolderCreated.archived_description).toEqual("folder complete");
|
||||
expect(officeFolderCreated.status).toEqual("ARCHIVED");
|
||||
|
||||
let officeFolderUnarchived: OfficeFolder = JSON.parse(JSON.stringify(officeFolder));
|
||||
officeFolderUnarchived.status = "LIVE";
|
||||
|
||||
const officeFolderUpdated = await OfficeFolderServiceTest.update(officeFolderCreated.uuid, officeFolderUnarchived);
|
||||
|
||||
expect(officeFolderUpdated.archived_description).toBeNull();
|
||||
expect(officeFolderUpdated.status).toEqual("LIVE");
|
||||
});
|
||||
});
|
||||
|
||||
describe("test get function", () => {
|
||||
it("should return an array of officeFolders", async () => {
|
||||
const officeFolders = await OfficeFolderServiceTest.get({});
|
||||
|
||||
// verify result typing
|
||||
expect(officeFolders).toBeInstanceOf(Array<OfficeFolder>);
|
||||
expect(officeFolders.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
@ -3,7 +3,7 @@ import "reflect-metadata";
|
||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { user, userContact, userContact_, user_ } from "./MockedData";
|
||||
import { user, userContact, userContact_, user_ } from "@Test/config/MockedData";
|
||||
import UsersRepository from "@Repositories/UsersRepository";
|
||||
import Container from "typedi";
|
||||
|
||||
@ -38,9 +38,9 @@ describe("test create function", () => {
|
||||
|
||||
// verify if user address is created in db
|
||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
|
||||
expect(addressForContactCreated?.address).toEqual(user.contact.address.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(user.contact.address.city);
|
||||
expect(addressForContactCreated?.address).toEqual(user.contact.address?.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(user.contact.address?.city);
|
||||
|
||||
// verify if user office is created in db
|
||||
const officeCreated = await prisma.offices.findUnique({ where: { uuid: userCreated.office_uuid } });
|
||||
@ -107,9 +107,9 @@ describe("test create function", () => {
|
||||
|
||||
// verify if user_ address is created in db
|
||||
const addressForContactCreated = await prisma.addresses.findUnique({ where: { uuid: contactCreated?.address_uuid } });
|
||||
expect(addressForContactCreated?.address).toEqual(user.contact.address.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(user.contact.address.city);
|
||||
expect(addressForContactCreated?.address).toEqual(user.contact.address?.address);
|
||||
expect(addressForContactCreated?.zip_code).toEqual(user.contact.address?.zip_code);
|
||||
expect(addressForContactCreated?.city).toEqual(user.contact.address?.city);
|
||||
|
||||
// verify if user joined the existing office
|
||||
const officeJoined = await prisma.offices.findUnique({ where: { uuid: userCreated.office_uuid } });
|
||||
@ -146,9 +146,9 @@ describe("test update function", () => {
|
||||
|
||||
// verify if user_ address is created in db
|
||||
const addressForExistingContact = await prisma.addresses.findUnique({ where: { uuid: existingContact?.address_uuid } });
|
||||
expect(addressForExistingContact?.address).toEqual(user_.contact.address.address);
|
||||
expect(addressForExistingContact?.zip_code).toEqual(user_.contact.address.zip_code);
|
||||
expect(addressForExistingContact?.city).toEqual(user_.contact.address.city);
|
||||
expect(addressForExistingContact?.address).toEqual(user_.contact.address?.address);
|
||||
expect(addressForExistingContact?.zip_code).toEqual(user_.contact.address?.zip_code);
|
||||
expect(addressForExistingContact?.city).toEqual(user_.contact.address?.city);
|
||||
|
||||
// verify if user_ joined the new office
|
||||
const officeCreated = await prisma.offices.findUnique({ where: { uuid: updatedUser.office_uuid } });
|
||||
|
Loading…
x
Reference in New Issue
Block a user