import { Helper } from "@nimee/tests"; import mongoose from "mongoose"; import { TicketClient } from "../src/ticket"; describe("ticket client", () => { test("when calling extract tickets from user events array with ticketsInfo array, all tickets extract correctly", async () => { // Arrange const eventId = new mongoose.Types.ObjectId(); const accountId = new mongoose.Types.ObjectId(); const ticketId1 = new mongoose.Types.ObjectId(); const ticketId2 = new mongoose.Types.ObjectId(); const helper = new Helper(); const userEvent1 = await helper.createUserEvent(eventId.toString(), accountId.toString(), [ticketId1.toString()], false); const userEvent2 = await helper.createUserEvent(eventId.toString(), accountId.toString(), [ticketId2.toString()], false); const userEvent3 = await helper.createUserEvent( eventId.toString(), accountId.toString(), [ticketId2.toString(), ticketId2.toString(), ticketId1.toString()], false ); // ACT const tickets = TicketClient.extractTickets([userEvent1, userEvent2, userEvent3]); // Assert expect(tickets.length).toBe(5); expect(tickets).toEqual([ ticketId1.toString(), ticketId2.toString(), ticketId2.toString(), ticketId2.toString(), ticketId1.toString(), ]); }); test("when calling extract tickets from user events array with ticket (legacy), all tickets extract correctly", async () => { // Arrange const eventId = new mongoose.Types.ObjectId(); const accountId = new mongoose.Types.ObjectId(); const ticketId1 = new mongoose.Types.ObjectId(); const ticketId2 = new mongoose.Types.ObjectId(); const helper = new Helper(); const userEvent1 = await helper.createUserEvent(eventId.toString(), accountId.toString(), [ticketId1.toString()], true); const userEvent2 = await helper.createUserEvent(eventId.toString(), accountId.toString(), [ticketId2.toString()], true); const userEvent3 = await helper.createUserEvent(eventId.toString(), accountId.toString(), [ticketId2.toString()], true); // ACT const tickets = TicketClient.extractTickets([userEvent1, userEvent2, userEvent3]); // Assert expect(tickets.length).toBe(3); expect(tickets).toEqual([ticketId1.toString(), ticketId2.toString(), ticketId2.toString()]); }); });