fix(testBack): add context
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2021-11-10 15:11:42 +01:00
parent 18aec14fe9
commit 41974669e5
2 changed files with 31 additions and 18 deletions

View File

@ -1,12 +1,13 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('loopback model Supplier', () => {
let supplierOne;
let supplierTwo;
beforeAll(async() => {
supplierOne = await app.models.Supplier.findById(1);
supplierTwo = await app.models.Supplier.findById(442);
supplierOne = await models.Supplier.findById(1);
supplierTwo = await models.Supplier.findById(442);
});
afterAll(async() => {
@ -18,7 +19,7 @@ describe('loopback model Supplier', () => {
it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => {
let error;
const expectedError = 'You can not select this payment method without a registered bankery account';
const supplier = await app.models.Supplier.findById(1);
const supplier = await models.Supplier.findById(1);
await supplier.updateAttribute('payMethodFk', 8)
.catch(e => {
@ -31,15 +32,27 @@ describe('loopback model Supplier', () => {
});
it('should not throw if the payMethod id is valid', async() => {
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
let error;
const supplier = await app.models.Supplier.findById(442);
const supplier = await models.Supplier.findById(442);
await supplier.updateAttribute('payMethodFk', 4)
.catch(e => {
error = e;
});
console.log(error);
expect(error).toBeDefined();
expect(error).not.toBeDefined();
});
});
});

View File

@ -9,40 +9,40 @@
"properties": {
"id": {
"id": true,
"type": "Number",
"type": "number",
"forceId": false
},
"originFk": {
"type": "Number",
"type": "number",
"required": true
},
"userFk": {
"type": "Number"
"type": "number"
},
"action": {
"type": "String",
"type": "string",
"required": true
},
"changedModel": {
"type": "String"
"type": "string"
},
"oldInstance": {
"type": "Object"
"type": "object"
},
"newInstance": {
"type": "Object"
"type": "object"
},
"creationDate": {
"type": "Date"
"type": "date"
},
"changedModelId": {
"type": "String"
"type": "string"
},
"changedModelValue": {
"type": "String"
"type": "string"
},
"description": {
"type": "String"
"type": "string"
}
},
"relations": {