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', () => { describe('loopback model Supplier', () => {
let supplierOne; let supplierOne;
let supplierTwo; let supplierTwo;
beforeAll(async() => { beforeAll(async() => {
supplierOne = await app.models.Supplier.findById(1); supplierOne = await models.Supplier.findById(1);
supplierTwo = await app.models.Supplier.findById(442); supplierTwo = await models.Supplier.findById(442);
}); });
afterAll(async() => { 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() => { it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => {
let error; let error;
const expectedError = 'You can not select this payment method without a registered bankery account'; 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) await supplier.updateAttribute('payMethodFk', 8)
.catch(e => { .catch(e => {
@ -31,15 +32,27 @@ describe('loopback model Supplier', () => {
}); });
it('should not throw if the payMethod id is valid', async() => { 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; let error;
const supplier = await app.models.Supplier.findById(442); const supplier = await models.Supplier.findById(442);
await supplier.updateAttribute('payMethodFk', 4) await supplier.updateAttribute('payMethodFk', 4)
.catch(e => { .catch(e => {
error = e; error = e;
}); });
console.log(error);
expect(error).toBeDefined(); expect(error).not.toBeDefined();
}); });
}); });
}); });

View File

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