backend unit tests adapted
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-07-29 17:40:45 +02:00
parent 8d682f4e03
commit 9578895f95
7 changed files with 116 additions and 16 deletions

View File

@ -7,7 +7,13 @@ describe('Claim createFromSales()', () => {
instance: 0,
quantity: 10
}];
const ctx = {req: {accessToken: {userId: 1}}};
const ctx = {
req: {
accessToken: {userId: 1},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
it('should create a new claim', async() => {
const tx = await app.models.Claim.beginTransaction({});

View File

@ -17,7 +17,14 @@ describe('sale deleteSales()', () => {
});
it('should throw an error if the ticket of the given sales is not editable', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
let ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
let error;
const sales = [{id: 1, instance: 0}, {id: 2, instance: 1}];
@ -33,7 +40,13 @@ describe('sale deleteSales()', () => {
});
it('should delete the sale', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
let ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
const sales = [{id: newSale.id, instance: 0}];
const ticketId = 16;

View File

@ -1,7 +1,14 @@
const app = require('vn-loopback/server/server');
describe('sale reserve()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
afterAll(async done => {
let ctx = {req: {accessToken: {userId: 9}}};
let params = {

View File

@ -17,7 +17,13 @@ describe('sale updatePrice()', () => {
});
it('should throw an error if the ticket is not editable', async() => {
let ctx = {req: {accessToken: {userId: 18}}};
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
let immutableSaleId = 1;
let price = 5;
@ -31,7 +37,14 @@ describe('sale updatePrice()', () => {
});
it('should return 0 if the price is an empty string', async() => {
let ctx = {req: {accessToken: {userId: 18}}};
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
let price = '';
await app.models.Sale.updatePrice(ctx, saleId, price);
@ -46,7 +59,14 @@ describe('sale updatePrice()', () => {
});
it('should now set price as a number in a string', async() => {
let ctx = {req: {accessToken: {userId: 18}}};
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
let price = '8';
await app.models.Sale.updatePrice(ctx, saleId, price);

View File

@ -1,7 +1,13 @@
const app = require('vn-loopback/server/server');
describe('sale updateQuantity()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
it('should throw an error if the quantity is not a number', async() => {
let error;

View File

@ -12,7 +12,13 @@ describe('ticket addSale()', () => {
});
it('should create a new sale for the ticket with id 13', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
const itemId = 4;
const quantity = 10;
newSale = await app.models.Ticket.addSale(ctx, ticketId, itemId, quantity);
@ -21,7 +27,13 @@ describe('ticket addSale()', () => {
});
it('should not be able to add a sale if the item quantity is not available', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
const itemId = 11;
const quantity = 10;
@ -36,7 +48,13 @@ describe('ticket addSale()', () => {
});
it('should not be able to add a sale if the ticket is not editable', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
const notEditableTicketId = 1;
const itemId = 4;
const quantity = 10;

View File

@ -35,7 +35,13 @@ describe('sale updateDiscount()', () => {
});
it('should throw an error if no sales were selected', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
let error;
const ticketId = 11;
const sales = [];
@ -51,7 +57,13 @@ describe('sale updateDiscount()', () => {
});
it('should throw an error if no sales belong to different tickets', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
let error;
const ticketId = 11;
const sales = [1, 14];
@ -67,7 +79,13 @@ describe('sale updateDiscount()', () => {
});
it('should throw an error if the ticket is invoiced already', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
let error;
const ticketId = 1;
const sales = [1];
@ -83,7 +101,13 @@ describe('sale updateDiscount()', () => {
});
it('should update the discount if the salesPerson has mana', async() => {
let ctx = {req: {accessToken: {userId: 18}}};
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
const ticketId = 11;
const sales = [originalSaleId];
const newDiscount = 100;
@ -105,7 +129,13 @@ describe('sale updateDiscount()', () => {
});
it('should update the discount and add company discount component if the worker does not have mana', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
const ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'localhost:5000'},
__: () => {}
}
};
const ticketId = 11;
const sales = [originalSaleId];
const newDiscount = 100;