refactor(clientCredit): refactor test

This commit is contained in:
Alex Moreno 2022-05-12 08:06:30 +02:00
parent a00728384f
commit af1fa8051f
10 changed files with 218 additions and 212 deletions

View File

@ -1,22 +1,22 @@
{
"name": "ClientConfig",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientConfig"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
"name": "ClientConfig",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientConfig"
}
},
"riskTolerance": {
"type": "Number"
},
"maxCreditRows": {
"type": "Number"
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"riskTolerance": {
"type": "number"
},
"maxCreditRows": {
"type": "number"
}
}
}
}

View File

@ -3,34 +3,34 @@
"description": "Client phone contacts",
"base": "Loggable",
"log": {
"model": "ClientLog",
"relation": "client",
"showField": "name"
"model": "ClientLog",
"relation": "client",
"showField": "name"
},
"options": {
"mysql": {
"table": "clientContact"
}
"mysql": {
"table": "clientContact"
}
},
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string"
},
"phone": {
"type": "string"
}
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string"
},
"phone": {
"type": "string"
}
},
"relations": {
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
}
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
}
}
}
}

View File

@ -1,26 +1,26 @@
{
"name": "ClientCreditLimit",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientCreditLimit"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"maxAmount": {
"type": "Number"
}
},
"relations": {
"role": {
"type": "belongsTo",
"model": "Role",
"foreignKey": "roleFk"
}
}
"name": "ClientCreditLimit",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientCreditLimit"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"maxAmount": {
"type": "Number"
}
},
"relations": {
"role": {
"type": "belongsTo",
"model": "Role",
"foreignKey": "roleFk"
}
}
}

View File

@ -1,36 +1,36 @@
{
"name": "ClientCredit",
"description": "Log of credit changes",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientCredit"
}
},
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
"name": "ClientCredit",
"description": "Log of credit changes",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientCredit"
}
},
"amount": {
"type": "Number"
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"amount": {
"type": "Number"
},
"created": {
"type": "date"
}
},
"created": {
"type": "date"
"relations": {
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
},
"worker": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "workerFk"
}
}
},
"relations": {
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
},
"worker": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "workerFk"
}
}
}

View File

@ -2,22 +2,22 @@
"name": "ClientRisk",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientRisk"
}
"mysql": {
"table": "clientRisk"
}
},
"properties": {
"clientFk": {
"type": "Number",
"id": true
},
"companyFk": {
"type": "Number",
"id": true
},
"amount": {
"type": "Number"
}
"clientFk": {
"type": "Number",
"id": true
},
"companyFk": {
"type": "Number",
"id": true
},
"amount": {
"type": "Number"
}
},
"relations": {
"client": {
@ -31,4 +31,4 @@
"foreignKey": "companyFk"
}
}
}
}

View File

@ -2,21 +2,21 @@
"name": "ClientUnpaid",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientUnpaid"
}
"mysql": {
"table": "clientUnpaid"
}
},
"properties": {
"clientFk": {
"type": "number",
"id": true
},
"dated": {
"type": "date"
},
"amount": {
"type": "Number"
}
"clientFk": {
"type": "number",
"id": true
},
"dated": {
"type": "date"
},
"amount": {
"type": "Number"
}
},
"relations": {
"client": {

View File

@ -1,20 +1,20 @@
{
"name": "ContactChannel",
"base": "VnModel",
"options": {
"mysql": {
"table": "contactChannel"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
"name": "ContactChannel",
"base": "VnModel",
"options": {
"mysql": {
"table": "contactChannel"
}
},
"name": {
"type": "string",
"required": true
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string",
"required": true
}
}
}
}

View File

@ -1,42 +1,42 @@
{
"name": "CreditClassification",
"description": "Clasified clients",
"base": "VnModel",
"options": {
"mysql": {
"table": "creditClassification"
}
},
"properties": {
"id": {
"id": true,
"type": "Number",
"description": "Identifier"
"name": "CreditClassification",
"description": "Clasified clients",
"base": "VnModel",
"options": {
"mysql": {
"table": "creditClassification"
}
},
"started": {
"type": "date",
"required": true,
"mysql": {
"columnName": "dateStart"
}
"properties": {
"id": {
"id": true,
"type": "Number",
"description": "Identifier"
},
"started": {
"type": "date",
"required": true,
"mysql": {
"columnName": "dateStart"
}
},
"finished": {
"type": "date",
"mysql": {
"columnName": "dateEnd"
}
}
},
"finished": {
"type": "date",
"mysql": {
"columnName": "dateEnd"
}
"relations": {
"customer": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "client"
},
"insurances": {
"type": "hasMany",
"model": "CreditInsurance",
"foreignKey": "creditClassification"
}
}
},
"relations": {
"customer": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "client"
},
"insurances": {
"type": "hasMany",
"model": "CreditInsurance",
"foreignKey": "creditClassification"
}
}
}
}

View File

@ -2,40 +2,40 @@
"name": "Recovery",
"base": "Loggable",
"log": {
"model": "ClientLog",
"relation": "client"
"model": "ClientLog",
"relation": "client"
},
"options": {
"mysql": {
"table": "recovery"
}
"mysql": {
"table": "recovery"
}
},
"properties": {
"id": {
"id": true,
"type": "Number",
"description": "Identifier"
},
"started": {
"type": "date",
"required": true
},
"finished": {
"type": "date"
},
"amount": {
"type": "Number",
"required": true
},
"period": {
"type": "Number"
}
"id": {
"id": true,
"type": "Number",
"description": "Identifier"
},
"started": {
"type": "date",
"required": true
},
"finished": {
"type": "date"
},
"amount": {
"type": "Number",
"required": true
},
"period": {
"type": "Number"
}
},
"relations": {
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
}
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
}
}
}
}

View File

@ -9,24 +9,29 @@ describe('Client Credit', () => {
const clientConfig = await models.ClientConfig.findOne({
where: {id: 1}
});
let rowsBefore;
let rowsAfter;
try {
const options = {transaction: tx};
const ctx = {options};
const salesAssistant = await models.Account.findOne({
where: {name: 'salesAssistant'}
}, ctx.options);
}, options);
rowsBefore = await models.ClientCredit.find({
where: {clientFk: instance.id},
}, options);
await models.ClientCredit.create({
amount: 355,
clientFk: instance.id,
workerFk: salesAssistant.id
}, ctx.options);
}, options);
rowsAfter = await models.ClientCredit.find({
where: {clientFk: instance.id},
}, ctx.options);
}, options);
await tx.rollback();
} catch (e) {
@ -34,6 +39,7 @@ describe('Client Credit', () => {
throw e;
}
expect(rowsBefore.length).toBeGreaterThanOrEqual(clientConfig.maxCreditRows);
expect(rowsAfter.length).toEqual(clientConfig.maxCreditRows);
});
});