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", "name": "ClientConfig",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "clientConfig" "table": "clientConfig"
} }
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
}, },
"riskTolerance": { "properties": {
"type": "Number" "id": {
}, "type": "number",
"maxCreditRows": { "id": true,
"type": "Number" "description": "Identifier"
},
"riskTolerance": {
"type": "number"
},
"maxCreditRows": {
"type": "number"
}
} }
}
} }

View File

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

View File

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

View File

@ -1,36 +1,36 @@
{ {
"name": "ClientCredit", "name": "ClientCredit",
"description": "Log of credit changes", "description": "Log of credit changes",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "clientCredit" "table": "clientCredit"
} }
},
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
}, },
"amount": { "validateUpsert": true,
"type": "Number" "properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"amount": {
"type": "Number"
},
"created": {
"type": "date"
}
}, },
"created": { "relations": {
"type": "date" "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", "name": "ClientRisk",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "clientRisk" "table": "clientRisk"
} }
}, },
"properties": { "properties": {
"clientFk": { "clientFk": {
"type": "Number", "type": "Number",
"id": true "id": true
}, },
"companyFk": { "companyFk": {
"type": "Number", "type": "Number",
"id": true "id": true
}, },
"amount": { "amount": {
"type": "Number" "type": "Number"
} }
}, },
"relations": { "relations": {
"client": { "client": {
@ -31,4 +31,4 @@
"foreignKey": "companyFk" "foreignKey": "companyFk"
} }
} }
} }

View File

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

View File

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

View File

@ -1,42 +1,42 @@
{ {
"name": "CreditClassification", "name": "CreditClassification",
"description": "Clasified clients", "description": "Clasified clients",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "creditClassification" "table": "creditClassification"
} }
},
"properties": {
"id": {
"id": true,
"type": "Number",
"description": "Identifier"
}, },
"started": { "properties": {
"type": "date", "id": {
"required": true, "id": true,
"mysql": { "type": "Number",
"columnName": "dateStart" "description": "Identifier"
} },
"started": {
"type": "date",
"required": true,
"mysql": {
"columnName": "dateStart"
}
},
"finished": {
"type": "date",
"mysql": {
"columnName": "dateEnd"
}
}
}, },
"finished": { "relations": {
"type": "date", "customer": {
"mysql": { "type": "belongsTo",
"columnName": "dateEnd" "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", "name": "Recovery",
"base": "Loggable", "base": "Loggable",
"log": { "log": {
"model": "ClientLog", "model": "ClientLog",
"relation": "client" "relation": "client"
}, },
"options": { "options": {
"mysql": { "mysql": {
"table": "recovery" "table": "recovery"
} }
}, },
"properties": { "properties": {
"id": { "id": {
"id": true, "id": true,
"type": "Number", "type": "Number",
"description": "Identifier" "description": "Identifier"
}, },
"started": { "started": {
"type": "date", "type": "date",
"required": true "required": true
}, },
"finished": { "finished": {
"type": "date" "type": "date"
}, },
"amount": { "amount": {
"type": "Number", "type": "Number",
"required": true "required": true
}, },
"period": { "period": {
"type": "Number" "type": "Number"
} }
}, },
"relations": { "relations": {
"client": { "client": {
"type": "belongsTo", "type": "belongsTo",
"model": "Client", "model": "Client",
"foreignKey": "clientFk" "foreignKey": "clientFk"
} }
} }
} }

View File

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