Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 174 additions & 34 deletions apis/api-journeys/src/app/modules/journey/journey.resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2457,65 +2457,205 @@ describe('JourneyResolver', () => {

describe('journeysArchive', () => {
it('archives an array of journeys', async () => {
prismaService.journey.findMany.mockResolvedValueOnce([journey])
expect(
await resolver.journeysArchive(accessibleJourneys, ['journeyId'])
).toEqual([journey])
expect(prismaService.journey.updateMany).toHaveBeenCalledWith({
where: { AND: [accessibleJourneys, { id: { in: ['journeyId'] } }] },
data: { status: JourneyStatus.archived, archivedAt: new Date() }
})
const journey2 = {
...journey,
id: 'journey2Id',
updatedAt: new Date('2025-11-19T12:34:56.647Z')
}
prismaService.journey.findMany.mockResolvedValueOnce([journey, journey2])
await resolver.journeysArchive(accessibleJourneys, [
'journeyId',
'journey2Id'
])
expect(prismaService.journey.findMany).toHaveBeenCalledWith({
where: { AND: [accessibleJourneys, { id: { in: ['journeyId'] } }] }
where: {
AND: [accessibleJourneys, { id: { in: ['journeyId', 'journey2Id'] } }]
}
})
expect(prismaService.journey.update).toHaveBeenCalledTimes(2)
expect(prismaService.journey.update).toHaveBeenNthCalledWith(1, {
where: { id: 'journeyId', updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.archived,
archivedAt: new Date(),
updatedAt: journey.updatedAt
}
})
expect(prismaService.journey.update).toHaveBeenNthCalledWith(2, {
where: { id: 'journey2Id', updatedAt: journey2.updatedAt },
data: {
status: JourneyStatus.archived,
archivedAt: new Date(),
updatedAt: journey2.updatedAt
}
})
})

it('keeps updatedAt the same when archiving a journey', async () => {
const originalUpdatedAt = new Date('2021-11-19T12:34:56.647Z')
const newJourney = { ...journey, updatedAt: originalUpdatedAt }
prismaService.journey.findMany.mockResolvedValueOnce([newJourney])
await resolver.journeysArchive(accessibleJourneys, ['journeyId'])
expect(prismaService.journey.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
updatedAt: originalUpdatedAt
})
})
)
})
})

describe('journeysDelete', () => {
it('deletes an array of journeys', async () => {
prismaService.journey.findMany.mockResolvedValueOnce([journey])
expect(
await resolver.journeysDelete(accessibleJourneys, ['journeyId'])
).toEqual([journey])
expect(prismaService.journey.updateMany).toHaveBeenCalledWith({
where: { AND: [accessibleJourneys, { id: { in: ['journeyId'] } }] },
data: { status: JourneyStatus.deleted, deletedAt: new Date() }
})
const journey2 = {
...journey,
id: 'journey2Id',
updatedAt: new Date('2025-11-19T12:34:56.647Z')
}
prismaService.journey.findMany.mockResolvedValueOnce([journey, journey2])
await resolver.journeysDelete(accessibleJourneys, [
'journeyId',
'journey2Id'
])
expect(prismaService.journey.findMany).toHaveBeenCalledWith({
where: { AND: [accessibleJourneys, { id: { in: ['journeyId'] } }] }
where: {
AND: [accessibleJourneys, { id: { in: ['journeyId', 'journey2Id'] } }]
}
})
expect(prismaService.journey.update).toHaveBeenCalledTimes(2)
expect(prismaService.journey.update).toHaveBeenNthCalledWith(1, {
where: { id: 'journeyId', updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.deleted,
deletedAt: new Date(),
updatedAt: journey.updatedAt
}
})
expect(prismaService.journey.update).toHaveBeenNthCalledWith(2, {
where: { id: 'journey2Id', updatedAt: journey2.updatedAt },
data: {
status: JourneyStatus.deleted,
deletedAt: new Date(),
updatedAt: journey2.updatedAt
}
})
})

it('keeps updatedAt the same when deleting a journey', async () => {
const originalUpdatedAt = new Date('2021-11-19T12:34:56.647Z')
const newJourney = { ...journey, updatedAt: originalUpdatedAt }
prismaService.journey.findMany.mockResolvedValueOnce([newJourney])
await resolver.journeysDelete(accessibleJourneys, ['journeyId'])
expect(prismaService.journey.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
updatedAt: originalUpdatedAt
})
})
)
})
})

describe('journeysTrash', () => {
it('trashes an array of journeys', async () => {
prismaService.journey.findMany.mockResolvedValueOnce([journey])
expect(
await resolver.journeysTrash(accessibleJourneys, ['journeyId'])
).toEqual([journey])
expect(prismaService.journey.updateMany).toHaveBeenCalledWith({
where: { AND: [accessibleJourneys, { id: { in: ['journeyId'] } }] },
data: { status: JourneyStatus.trashed, trashedAt: new Date() }
})
const journey2 = {
...journey,
id: 'journey2Id',
updatedAt: new Date('2025-11-19T12:34:56.647Z')
}
prismaService.journey.findMany.mockResolvedValueOnce([journey, journey2])
await resolver.journeysTrash(accessibleJourneys, [
'journeyId',
'journey2Id'
])
expect(prismaService.journey.findMany).toHaveBeenCalledWith({
where: { AND: [accessibleJourneys, { id: { in: ['journeyId'] } }] }
where: {
AND: [accessibleJourneys, { id: { in: ['journeyId', 'journey2Id'] } }]
}
})
expect(prismaService.journey.update).toHaveBeenCalledTimes(2)
expect(prismaService.journey.update).toHaveBeenNthCalledWith(1, {
where: { id: 'journeyId', updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.trashed,
trashedAt: new Date(),
updatedAt: journey.updatedAt
}
})
expect(prismaService.journey.update).toHaveBeenNthCalledWith(2, {
where: { id: 'journey2Id', updatedAt: journey2.updatedAt },
data: {
status: JourneyStatus.trashed,
trashedAt: new Date(),
updatedAt: journey2.updatedAt
}
})
})

it('keeps updatedAt the same when trashing a journey', async () => {
const originalUpdatedAt = new Date('2021-11-19T12:34:56.647Z')
const newJourney = { ...journey, updatedAt: originalUpdatedAt }
prismaService.journey.findMany.mockResolvedValueOnce([newJourney])
await resolver.journeysTrash(accessibleJourneys, ['journeyId'])
expect(prismaService.journey.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
updatedAt: originalUpdatedAt
})
})
)
})
})

describe('journeysRestore', () => {
it('restores a Journey', async () => {
prismaService.journey.findMany.mockResolvedValueOnce([journey])
await resolver.journeysRestore(accessibleJourneys, ['journeyId'])
it('restores an array of journeys', async () => {
const journey2 = {
...journey,
id: 'journey2Id',
updatedAt: new Date('2025-11-19T12:34:56.647Z')
}
prismaService.journey.findMany.mockResolvedValueOnce([journey, journey2])
await resolver.journeysRestore(accessibleJourneys, [
'journeyId',
'journey2Id'
])
expect(prismaService.journey.findMany).toHaveBeenCalledWith({
where: {
AND: [accessibleJourneys, { id: { in: ['journeyId'] } }]
AND: [accessibleJourneys, { id: { in: ['journeyId', 'journey2Id'] } }]
}
})
expect(prismaService.journey.update).toHaveBeenCalledWith({
where: { id: 'journeyId' },
data: { status: JourneyStatus.published, publishedAt: new Date() }
expect(prismaService.journey.update).toHaveBeenCalledTimes(2)
expect(prismaService.journey.update).toHaveBeenNthCalledWith(1, {
where: { id: 'journeyId', updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.published,
publishedAt: new Date(),
updatedAt: journey.updatedAt
}
})
expect(prismaService.journey.update).toHaveBeenNthCalledWith(2, {
where: { id: 'journey2Id', updatedAt: journey2.updatedAt },
data: {
status: JourneyStatus.published,
publishedAt: new Date(),
updatedAt: journey2.updatedAt
}
})
})

it('keeps updatedAt the same when restoring a journey', async () => {
const originalUpdatedAt = new Date('2021-11-19T12:34:56.647Z')
const newJourney = { ...journey, updatedAt: originalUpdatedAt }
prismaService.journey.findMany.mockResolvedValueOnce([newJourney])
await resolver.journeysRestore(accessibleJourneys, ['journeyId'])
expect(prismaService.journey.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
updatedAt: originalUpdatedAt
})
})
)
})
})

Expand Down
62 changes: 45 additions & 17 deletions apis/api-journeys/src/app/modules/journey/journey.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,22 @@ export class JourneyResolver {
accessibleJourneys: Prisma.JourneyWhereInput,
@Args('ids') ids: string[]
): Promise<Journey[]> {
await this.prismaService.journey.updateMany({
where: { AND: [accessibleJourneys, { id: { in: ids } }] },
data: { status: JourneyStatus.archived, archivedAt: new Date() }
})
return await this.prismaService.journey.findMany({
const results = await this.prismaService.journey.findMany({
where: { AND: [accessibleJourneys, { id: { in: ids } }] }
})
return await Promise.all(
results.map(
async (journey) =>
await this.prismaService.journey.update({
where: { id: journey.id, updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.archived,
archivedAt: new Date(),
updatedAt: journey.updatedAt
}
})
)
)
}

@Mutation()
Expand All @@ -977,13 +986,22 @@ export class JourneyResolver {
accessibleJourneys: Prisma.JourneyWhereInput,
@Args('ids') ids: string[]
): Promise<Journey[]> {
await this.prismaService.journey.updateMany({
where: { AND: [accessibleJourneys, { id: { in: ids } }] },
data: { status: JourneyStatus.deleted, deletedAt: new Date() }
})
return await this.prismaService.journey.findMany({
const results = await this.prismaService.journey.findMany({
where: { AND: [accessibleJourneys, { id: { in: ids } }] }
})
return await Promise.all(
results.map(
async (journey) =>
await this.prismaService.journey.update({
where: { id: journey.id, updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.deleted,
deletedAt: new Date(),
updatedAt: journey.updatedAt
}
})
)
)
}

@Mutation()
Expand All @@ -993,13 +1011,22 @@ export class JourneyResolver {
accessibleJourneys: Prisma.JourneyWhereInput,
@Args('ids') ids: string[]
): Promise<Journey[]> {
await this.prismaService.journey.updateMany({
where: { AND: [accessibleJourneys, { id: { in: ids } }] },
data: { status: JourneyStatus.trashed, trashedAt: new Date() }
})
return await this.prismaService.journey.findMany({
const results = await this.prismaService.journey.findMany({
where: { AND: [accessibleJourneys, { id: { in: ids } }] }
})
return await Promise.all(
results.map(
async (journey) =>
await this.prismaService.journey.update({
where: { id: journey.id, updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.trashed,
trashedAt: new Date(),
updatedAt: journey.updatedAt
}
})
)
)
}

@Mutation()
Expand All @@ -1016,10 +1043,11 @@ export class JourneyResolver {
results.map(
async (journey) =>
await this.prismaService.journey.update({
where: { id: journey.id },
where: { id: journey.id, updatedAt: journey.updatedAt },
data: {
status: JourneyStatus.published,
publishedAt: new Date()
publishedAt: new Date(),
updatedAt: journey.updatedAt
}
})
)
Expand Down