refactor(clientCredit): refactor test
This commit is contained in:
parent
a00728384f
commit
af1fa8051f
modules/client/back/models
|
@ -8,15 +8,15 @@
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "Number",
|
"type": "number",
|
||||||
"id": true,
|
"id": true,
|
||||||
"description": "Identifier"
|
"description": "Identifier"
|
||||||
},
|
},
|
||||||
"riskTolerance": {
|
"riskTolerance": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"maxCreditRows": {
|
"maxCreditRows": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -33,4 +33,4 @@
|
||||||
"foreignKey": "clientFk"
|
"foreignKey": "clientFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,4 +31,4 @@
|
||||||
"foreignKey": "companyFk"
|
"foreignKey": "companyFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -38,4 +38,4 @@
|
||||||
"foreignKey": "clientFk"
|
"foreignKey": "clientFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue