Skip to content

Commit

Permalink
Fix QR code stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyNTH committed Feb 19, 2025
1 parent 6b10066 commit c538fe7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 58 deletions.
22 changes: 6 additions & 16 deletions components/ui/Input/UiInputTicketScanner.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ import InvalidTicketQRCodeException from '~~/exceptions/InvalidTicketQRCodeExcep
import type { TicketQRCodeData } from '~~/types/ticket';
const props = withDefaults(
defineProps<{
on?: boolean;
pauseOnDecode?: boolean;
}>(),
{
on: true,
pauseOnDecode: true
}
defineProps<{ on?: boolean; pauseOnDecode?: boolean }>(),
{ on: true, pauseOnDecode: true }
);
const cameraReset = ref(false);
Expand All @@ -33,10 +27,7 @@ const emit = defineEmits<{
(event: 'unable', message: string): void;
(
event: 'scanned',
data: {
ticketData: TicketQRCodeData;
reenable: () => void;
}
data: { ticketData: TicketQRCodeData; reenable: () => void }
): void;
(event: 'invalidCode'): void;
}>();
Expand All @@ -56,9 +47,8 @@ function onTrackEvent(detectedCodes: any, ctx: any) {
}
}
async function cameraOn(promise: Promise<any>) {
async function cameraOn(c: MediaTrackCapabilities) {
try {
await promise;
emit('ready');
} catch (error: any) {
let errorMessage;
Expand Down Expand Up @@ -90,11 +80,11 @@ async function cameraOn(promise: Promise<any>) {
emit('unable', errorMessage);
}
}
function onDetect(string: [string]) {
function onDetect(detectedCodes: { rawValue: string }[]) {
new Audio('/audio/beep_single.mp3').play();
try {
const rawValue = JSON.parse(JSON.stringify(string[0])).rawValue;
const rawValue = `${JSON.stringify(detectedCodes.map((code) => code.rawValue))} ${new Date().getTime()}`;
const ticketData = Ticket.dataFromQRCode(rawValue);
if (props.pauseOnDecode) {
cameraReset.value = true;
Expand Down
53 changes: 11 additions & 42 deletions tests/unit/pages/booking/Book.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,10 @@ describe('Create Booking Page', () => {
bookingComponent = await mount(Book, {
shallow: false,
routeInfo: {
params: Object.assign(
{},
{
slug: 'legally-ginger'
},
routeParams
)
params: Object.assign({}, { slug: 'legally-ginger' }, routeParams)
},
apollo: {
queryResponses
},
global: {
components: { NuxtPage: fakePage ?? generateFakeNuxtPage() }
}
apollo: { queryResponses },
global: { components: { NuxtPage: fakePage ?? generateFakeNuxtPage() } }
});
}

Expand Down Expand Up @@ -74,9 +64,7 @@ describe('Create Booking Page', () => {
});

it('has a nuxt child', async () => {
await bookingComponent.setData({
ticketMatrix: 'fakeMatrix'
});
await bookingComponent.setData({ ticketMatrix: 'fakeMatrix' });

const nuxtChild = bookingComponent.findComponent({ name: 'NuxtPage' });
expect(nuxtChild.exists()).to.be.true;
Expand All @@ -88,20 +76,15 @@ describe('Create Booking Page', () => {
it('reacts to the child emitting select performance event', async () => {
const childComponent = bookingComponent.findComponent({ name: 'NuxtPage' });

await childComponent.vm.$emit('select-performance', {
id: 1
});
await childComponent.vm.$emit('select-performance', { id: 1 });

expect(bookingComponent.vm.booking.performance.id).to.eq(1);

const router = useRouter();
expect(router.push).toHaveBeenCalledWith({
hash: '#booking-view',
name: 'production-slug-book-performanceId-warnings',
params: {
slug: 'legally-ginger',
performanceId: 1
}
params: { slug: 'legally-ginger', performanceId: 1 }
});
});

Expand All @@ -116,20 +99,15 @@ describe('Create Booking Page', () => {
expect(router.push).toHaveBeenCalledWith({
hash: '#booking-view',
name: 'production-slug-book-performanceId-tickets',
params: {
slug: 'legally-ginger',
performanceId: null
}
params: { slug: 'legally-ginger', performanceId: null }
});
});

describe('with performance id', () => {
beforeEach(async () => {
await mountComponent({ performanceId: 1 }, [
GenericApolloResponse('production', Production({}, true)),
GenericApolloResponse('me', {
bookings: GenericNodeConnection()
}),
GenericApolloResponse('me', { bookings: GenericNodeConnection() }),
GenericApolloResponse('performance', Performance())
]);

Expand All @@ -152,10 +130,7 @@ describe('Create Booking Page', () => {
expect(router.push).toHaveBeenCalledWith({
name: 'production-slug-book-performanceId-warnings',
hash: '#booking-view',
params: {
performanceId: 1,
slug: 'legally-ginger'
}
params: { performanceId: 1, slug: 'legally-ginger' }
});
});
});
Expand Down Expand Up @@ -228,10 +203,7 @@ describe('Create Booking Page', () => {
expect(router.replace).toHaveBeenCalledWith({
hash: '#booking-view',
name: 'production-slug-book-performanceId-tickets',
params: {
slug: 'legally-ginger',
performanceId: 1
}
params: { slug: 'legally-ginger', performanceId: 1 }
});
mock.mockReset();
});
Expand All @@ -250,10 +222,7 @@ describe('Create Booking Page', () => {
expect(router.push).toHaveBeenCalledWith({
hash: '#booking-view',
name: 'production-slug-book',
params: {
slug: 'legally-ginger',
performanceId: 1
}
params: { slug: 'legally-ginger', performanceId: 1 }
});
shouldBeUsedMock.mockReset();
eligableMock.mockReset();
Expand Down

0 comments on commit c538fe7

Please sign in to comment.