test: refs #3979 quito clone parametro group porque no se usa
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
2fb60aeed3
commit
4cb82524cb
|
@ -78,7 +78,7 @@ module.exports = Self => {
|
|||
const sales = await models.Sale.find(filterTicket, myOptions);
|
||||
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 = [];
|
||||
|
||||
for (const clonedTicket of clonedTickets) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 myOptions = {};
|
||||
let tx;
|
||||
|
@ -28,8 +28,6 @@ module.exports = Self => {
|
|||
|
||||
const mappedTickets = new Map();
|
||||
|
||||
if (group) ticketsIds = [ticketsIds[0]];
|
||||
|
||||
for (let ticketId of ticketsIds) {
|
||||
const newTicket = await createTicket(
|
||||
ctx,
|
||||
|
@ -43,7 +41,7 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
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({
|
||||
ticketFk: newTicketId,
|
||||
|
|
|
@ -47,7 +47,6 @@ module.exports = Self => {
|
|||
salesIds,
|
||||
servicesIds,
|
||||
withWarehouse,
|
||||
false,
|
||||
true,
|
||||
myOptions
|
||||
);
|
||||
|
|
|
@ -25,16 +25,15 @@ describe('Ticket cloning - clone function', () => {
|
|||
});
|
||||
|
||||
afterEach(async() => {
|
||||
await tx.commit();
|
||||
await tx.rollback();
|
||||
});
|
||||
|
||||
it('should create new tickets with cloned sales with warehouse', async() => {
|
||||
const salesIds = [1, 2, 3];
|
||||
const servicesIds = [];
|
||||
const withWarehouse = true;
|
||||
const group = 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.length).toBeGreaterThan(0);
|
||||
|
@ -43,9 +42,9 @@ describe('Ticket cloning - clone function', () => {
|
|||
it('should handle negative quantities correctly', async() => {
|
||||
const negative = true;
|
||||
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) {
|
||||
const sales = await models.Sale.find({where: {ticketFk: ticket.id}}, options);
|
||||
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() => {
|
||||
const servicesIds = [2];
|
||||
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) {
|
||||
const sale = await models.Sale.findOne({where: {ticketFk: ticket.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() => {
|
||||
const negative = true;
|
||||
const salesIds = [1, 2, 3, 4, 5];
|
||||
const servicesIds = [];
|
||||
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');
|
||||
} catch (error) {
|
||||
expect(error).toBeDefined();
|
||||
|
|
Loading…
Reference in New Issue