Skip to content

Commit

Permalink
refactor(locksmith): getEventFixture (#13779)
Browse files Browse the repository at this point in the history
* getEventFixture

* removed extra code
  • Loading branch information
julien51 committed May 3, 2024
1 parent a3a60c2 commit 08a0c89
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 78 deletions.
17 changes: 9 additions & 8 deletions locksmith/__tests__/controllers/v2/ticketsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as metadataOperations from '../../../src/operations/metadataOperations'
import app from '../../app'
import { beforeAll, vi } from 'vitest'
import { saveEvent } from '../../../src/operations/eventOperations'
import testEvents from '../../fixtures/events'
import { getEventFixture } from '../../fixtures/events'
import { CheckoutConfig, EventData } from '../../../src/models'

function* keyIdGen() {
Expand Down Expand Up @@ -67,16 +67,17 @@ describe('tickets endpoint', () => {
await CheckoutConfig.truncate()
fetchMock.enableMocks()
// create an event
const eventParams = { ...testEvents[0] }
eventParams.checkoutConfig = {
config: {
locks: {
[lockAddress]: {
network,
const eventParams = getEventFixture({
checkoutConfig: {
config: {
locks: {
[lockAddress]: {
network,
},
},
},
},
}
})
eventParams.data.notifyCheckInUrls = [notifyCheckInUrl]
await saveEvent(eventParams, owner)
})
Expand Down
32 changes: 0 additions & 32 deletions locksmith/__tests__/fixtures/events.json

This file was deleted.

36 changes: 36 additions & 0 deletions locksmith/__tests__/fixtures/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { merge } from 'lodash'
export const getEventFixture = (event = {}) => {
return merge(
{
data: {
name: 'An Event',
image: 'https://host.tld/image.jpg',
attributes: [
{ trait_type: 'event_start_date', value: '2024-05-22' },
{ trait_type: 'event_start_time', value: '08:30' },
{ trait_type: 'event_end_date', value: '2024-05-22' },
{ trait_type: 'event_end_time', value: '14:00' },
{ trait_type: 'event_timezone', value: 'America/New_York' },
{
trait_type: 'event_address',
value: '29 Little W 12th St, New York, NY 10014, USA',
},
],
description: 'An Event',
ticket: {
event_start_date: '2024-05-22',
event_start_time: '08:30',
event_end_date: '2024-05-22',
event_end_time: '14:00',
event_timezone: 'America/New_York',
event_address: '29 Little W 12th St, New York, NY 10014, USA',
},
requiresApproval: false,
emailSender: 'Julien Genestoux',
replyTo: 'julien@unlock-protocol.com',
},
checkoutConfig: { config: { locks: {} } },
},
event
)
}
60 changes: 22 additions & 38 deletions locksmith/__tests__/operations/eventOperations.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { vi } from 'vitest'

import { CheckoutConfig, EventData } from '../../src/models'
import { getEventFixture } from '../../__tests__/fixtures/events'

import {
createEventSlug,
getEventBySlug,
saveEvent,
} from '../../src/operations/eventOperations'

describe('eventOperations', () => {
beforeEach(async () => {
await EventData.truncate()
Expand Down Expand Up @@ -34,10 +39,10 @@ describe('eventOperations', () => {
describe('saveEvent', () => {
it('should not override an event if no slug is provided', async () => {
expect.assertions(2)
const eventParams = {
const eventParams = getEventFixture({
data: { name: 'my party' },
checkoutConfig: { config: { locks: {} } },
}
})
const [event] = await saveEvent(eventParams, '0x123')
expect(event.slug).toEqual('my-party')
const [anotherEvent] = await saveEvent(eventParams, '0x123')
Expand All @@ -46,10 +51,10 @@ describe('eventOperations', () => {

it('should override an event if a slug is provided', async () => {
expect.assertions(1)
const eventParams = {
const eventParams = getEventFixture({
data: { name: 'my party' },
checkoutConfig: { config: { locks: {} } },
}
})
const [event] = await saveEvent(eventParams, '0x123')
const [sameEvent] = await saveEvent(
{
Expand All @@ -66,44 +71,23 @@ describe('eventOperations', () => {

it('should save requiresAppoval when applicable', async () => {
expect.assertions(2)
const eventParams = {
data: { name: 'my rsvp party', requiresApproval: true },
const eventParams = getEventFixture({
data: {
name: 'My RSVP party',
requiresApproval: true,
},
checkoutConfig: { config: { locks: {} } },
}
})
const [{ slug }] = await saveEvent(eventParams, '0x123')
const savedEvent = await getEventBySlug(slug, false)
expect(savedEvent.slug).toEqual('my-rsvp-party')
expect(savedEvent?.data.requiresApproval).toEqual(true)
})

it('should save a full event with all its data', async () => {
const eventParams = {
const eventParams = getEventFixture({
data: {
name: 'An Event with all the data',
image: 'https://host.tld/image.jpg',
attributes: [
{ trait_type: 'event_start_date', value: '2024-05-22' },
{ trait_type: 'event_start_time', value: '08:30' },
{ trait_type: 'event_end_date', value: '2024-05-22' },
{ trait_type: 'event_end_time', value: '14:00' },
{ trait_type: 'event_timezone', value: 'America/New_York' },
{
trait_type: 'event_address',
value: '29 Little W 12th St, New York, NY 10014, USA',
},
],
description: 'An Event with all the data',
ticket: {
event_start_date: '2024-05-22',
event_start_time: '08:30',
event_end_date: '2024-05-22',
event_end_time: '14:00',
event_timezone: 'America/New_York',
event_address: '29 Little W 12th St, New York, NY 10014, USA',
},
requiresApproval: false,
emailSender: 'Julien Genestoux',
replyTo: 'julien@unlock-protocol.com',
name: 'A unique event!',
},
checkoutConfig: {
name: 'Checkout config for An Event with all the data',
Expand Down Expand Up @@ -134,13 +118,13 @@ describe('eventOperations', () => {
},
},
},
}
})
const [{ slug }] = await saveEvent(eventParams, '0x123')
const savedEvent = await getEventBySlug(slug, true)
expect(savedEvent.slug).toEqual('an-event-with-all-the-data')
expect(savedEvent.slug).toEqual('a-unique-event')
expect(savedEvent?.data).toEqual({
name: 'An Event with all the data',
slug: 'an-event-with-all-the-data',
name: 'A unique event!',
slug: 'a-unique-event',
image: 'https://host.tld/image.jpg',
ticket: {
event_address: '29 Little W 12th St, New York, NY 10014, USA',
Expand All @@ -162,7 +146,7 @@ describe('eventOperations', () => {
trait_type: 'event_address',
},
],
description: 'An Event with all the data',
description: 'An Event',
emailSender: 'Julien Genestoux',
requiresApproval: false,
})
Expand Down

0 comments on commit 08a0c89

Please sign in to comment.