#6436 Definir funcion global que añada ctx #2232

Merged
jon merged 28 commits from 6436_jasmine_beforeAll into dev 2024-07-03 07:56:18 +00:00
16 changed files with 18 additions and 41 deletions
Showing only changes of commit 665d03f048 - Show all commits

View File

@ -1,12 +1,12 @@
const models = require('vn-loopback/server/server').models;
describe('userConfig getUserConfig()', () => {
const {ctx} = beforeAll;
it(`should return the configuration data of a given user`, async() => {
const tx = await models.Item.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {req: {accessToken: {userId: 9}}};
const result = await models.UserConfig.getUserConfig(ctx, options);
expect(result.warehouseFk).toEqual(1);

View File

@ -1,11 +1,11 @@
const models = require('vn-loopback/server/server').models;
describe('Client getCard()', () => {
const {ctx} = beforeAll;
it('should receive a formated card of Bruce Wayne', async() => {
const tx = await models.Client.beginTransaction({});
try {
const ctx = {req: {accessToken: {userId: 9}}};
const options = {transaction: tx};
const id = 1101;

View File

@ -1,9 +1,9 @@
const models = require('vn-loopback/server/server').models;
describe('client getDebt()', () => {
const {ctx} = beforeAll;
it('should return the client debt', async() => {
const tx = await models.Client.beginTransaction({});
const ctx = {req: {accessToken: {userId: 9}}};
try {
const options = {transaction: tx};

View File

@ -1,12 +1,12 @@
const models = require('vn-loopback/server/server').models;
describe('client sendSms()', () => {
const {ctx} = beforeAll;
it('should now send a message and log it', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}}};
const id = 1101;
const destination = 222222222;
const message = 'this is the message created in a test';

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('client summary()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
it('should return a summary object containing data', async() => {
const clientId = 1101;
const tx = await models.Client.beginTransaction({});

View File

@ -1,13 +1,10 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
const activeCtx = {accessToken: {userId: 9}};
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('entry importBuysPreview()', () => {
const entryId = 1;
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
mockLoopBackContext();
});
it('should return the buys with the calculated packagingFk', async() => {

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('invoiceOut book()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
const invoiceOutId = 5;
it('should update the booked property', async() => {

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('order addToOrder()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
const orderId = 8;
it('should add a row to a given order', async() => {
const tx = await models.Order.beginTransaction({});

View File

@ -1,11 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('order filter()', () => {
const ctx = {
req: {accessToken: {userId: 9}},
args: {},
params: {}
};
const {ctx} = beforeAll;
it('should call the filter method with a basic search', async() => {
const myCtx = Object.assign({}, ctx);

View File

@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models;
const UserError = require('vn-loopback/util/user-error');
describe('order new()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
it('should throw an error if the client isnt active', async() => {
const tx = await models.Order.beginTransaction({});

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('order newFromTicket()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
it('should create a new order from an existing ticket', async() => {
const tx = await models.Order.beginTransaction({});

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('expeditionState addExpeditionState()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
it('should update the expedition states', async() => {
const tx = await models.ExpeditionState.beginTransaction({});
try {

View File

@ -1,6 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('sale recalculatePrice()', () => {
const {ctx} = beforeAll;
it('should update the sale price', async() => {
const tx = await models.Sale.beginTransaction({});
const sales = [
@ -10,7 +11,6 @@ describe('sale recalculatePrice()', () => {
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}}};
const response = await models.Sale.recalculatePrice(ctx, sales, options);
expect(response[0].affectedRows).toBeDefined();
@ -30,7 +30,6 @@ describe('sale recalculatePrice()', () => {
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}}};
const immutableSale = [{id: 1, ticketFk: 1}];
await models.Sale.recalculatePrice(ctx, immutableSale, options);

View File

@ -1,12 +1,7 @@
const models = require('vn-loopback/server/server').models;
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('sale updateConcept()', () => {
beforeAll(async() => {
mockLoopBackContext();
});
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
const saleId = 25;
it('should throw if ID was undefined', async() => {

View File

@ -1,19 +1,9 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
describe('ticket-request deny()', () => {
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
mockLoopBackContext();
});
it('should return the denied ticket request', async() => {

View File

@ -5,7 +5,7 @@ describe('Termograph createThermograph()', () => {
const model = 'DISPOSABLE';
const temperatureFk = 'COOL';
const warehouseId = 1;
const ctx = {req: {accessToken: {userId: 9}}};
const {ctx} = beforeAll;
it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
const tx = await models.Thermograph.beginTransaction({});