test: refs #3979 quito clone parametro group porque no se usa
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2024-01-04 08:37:34 +01:00
parent 2fb60aeed3
commit 4cb82524cb
4 changed files with 10 additions and 23 deletions

View File

@ -78,7 +78,7 @@ module.exports = Self => {
const sales = await models.Sale.find(filterTicket, myOptions); const sales = await models.Sale.find(filterTicket, myOptions);
const salesIds = sales.map(sale => sale.id); const salesIds = sales.map(sale => sale.id);
const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, false, myOptions); const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, myOptions);
const clonedTicketIds = []; const clonedTicketIds = [];
for (const clonedTicket of clonedTickets) { for (const clonedTicket of clonedTickets) {

View File

@ -1,5 +1,5 @@
module.exports = Self => { module.exports = Self => {
Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, group, negative, options) => { Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, negative, options) => {
const models = Self.app.models; const models = Self.app.models;
const myOptions = {}; const myOptions = {};
let tx; let tx;
@ -28,8 +28,6 @@ module.exports = Self => {
const mappedTickets = new Map(); const mappedTickets = new Map();
if (group) ticketsIds = [ticketsIds[0]];
for (let ticketId of ticketsIds) { for (let ticketId of ticketsIds) {
const newTicket = await createTicket( const newTicket = await createTicket(
ctx, ctx,
@ -43,7 +41,7 @@ module.exports = Self => {
} }
for (const sale of sales) { for (const sale of sales) {
const newTicketId = group ? ticketsIds : mappedTickets.get(sale.ticketFk); const newTicketId = mappedTickets.get(sale.ticketFk);
const createdSale = await models.Sale.create({ const createdSale = await models.Sale.create({
ticketFk: newTicketId, ticketFk: newTicketId,

View File

@ -47,7 +47,6 @@ module.exports = Self => {
salesIds, salesIds,
servicesIds, servicesIds,
withWarehouse, withWarehouse,
false,
true, true,
myOptions myOptions
); );

View File

@ -25,16 +25,15 @@ describe('Ticket cloning - clone function', () => {
}); });
afterEach(async() => { afterEach(async() => {
await tx.commit(); await tx.rollback();
}); });
it('should create new tickets with cloned sales with warehouse', async() => { it('should create new tickets with cloned sales with warehouse', async() => {
const salesIds = [1, 2, 3]; const salesIds = [1, 2, 3];
const servicesIds = []; const servicesIds = [];
const withWarehouse = true; const withWarehouse = true;
const group = false;
const negative = false; const negative = false;
const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, group, negative, options); const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, negative, options);
expect(newTickets).toBeDefined(); expect(newTickets).toBeDefined();
expect(newTickets.length).toBeGreaterThan(0); expect(newTickets.length).toBeGreaterThan(0);
@ -43,9 +42,9 @@ describe('Ticket cloning - clone function', () => {
it('should handle negative quantities correctly', async() => { it('should handle negative quantities correctly', async() => {
const negative = true; const negative = true;
const salesIds = [7, 8]; const salesIds = [7, 8];
const newTickets = await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); const servicesIds = [];
const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options);
// Verify that the cloned sales have negative quantities
for (const ticket of newTickets) { for (const ticket of newTickets) {
const sales = await models.Sale.find({where: {ticketFk: ticket.id}}, options); const sales = await models.Sale.find({where: {ticketFk: ticket.id}}, options);
sales.forEach(sale => { sales.forEach(sale => {
@ -54,21 +53,11 @@ describe('Ticket cloning - clone function', () => {
} }
}); });
it('should group sales into a single ticket if group is true', async() => {
const salesIds = [1, 2, 3, 4, 5];
const group = true;
const newTickets = await models.Sale.clone(ctx, salesIds, [], false, group, false, options);
expect(newTickets.length).toEqual(1);
// Additional assertions for ticket grouping
});
it('should create new components and services for cloned tickets', async() => { it('should create new components and services for cloned tickets', async() => {
const servicesIds = [2]; const servicesIds = [2];
const salesIds = [5]; const salesIds = [5];
const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, false, options); const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, options);
// Verify that components and services are created for each new ticket
for (const ticket of newTickets) { for (const ticket of newTickets) {
const sale = await models.Sale.findOne({where: {ticketFk: ticket.id}}, options); const sale = await models.Sale.findOne({where: {ticketFk: ticket.id}}, options);
const components = await models.SaleComponent.find({where: {saleFk: sale.id}}, options); const components = await models.SaleComponent.find({where: {saleFk: sale.id}}, options);
@ -82,8 +71,9 @@ describe('Ticket cloning - clone function', () => {
it('should handle transaction rollback on error', async() => { it('should handle transaction rollback on error', async() => {
const negative = true; const negative = true;
const salesIds = [1, 2, 3, 4, 5]; const salesIds = [1, 2, 3, 4, 5];
const servicesIds = [];
try { try {
await models.Sale.clone(ctx, salesIds, [], false, false, negative, options); await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options);
fail('Expected error was not thrown'); fail('Expected error was not thrown');
} catch (error) { } catch (error) {
expect(error).toBeDefined(); expect(error).toBeDefined();