Skip to content

Commit

Permalink
Remove hardcoded uuids
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Jan 3, 2024
1 parent d3ca1b4 commit e60d16d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
30 changes: 15 additions & 15 deletions test/spec/controllers/eventForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Controller: eventForm', function () {
scope.previewForm();

expect($location.path).toHaveBeenCalledWith(
'/preview/c63b8abf-52ff-4cc4-afbc-5923b01f1ab0/page/',
`/preview/${testData.conference.id}/page/`,
);
});
});
Expand All @@ -143,7 +143,7 @@ describe('Controller: eventForm', function () {
});

it('refuses to delete pages with an email profile question', () => {
scope.deletePage('5c69bfcc-9e35-4bd8-8358-fe50fd86052d');
scope.deletePage(testData.conference.registrationPages[0].id);

expect(modalMessage.error).toHaveBeenCalledTimes(1);
expect(modalMessage.error.calls.argsFor(0)[0].message).toBe(
Expand All @@ -152,7 +152,7 @@ describe('Controller: eventForm', function () {
});

it('refuses to delete pages with a name profile question', () => {
scope.deletePage('7b4c19df-7377-4d37-90fb-5b262bb66d1a');
scope.deletePage(testData.conference.registrationPages[1].id);

expect(modalMessage.error).toHaveBeenCalledTimes(1);
expect(modalMessage.error.calls.argsFor(0)[0].message).toBe(
Expand All @@ -161,7 +161,7 @@ describe('Controller: eventForm', function () {
});

it('refuses to delete pages with a waiver profile question', () => {
scope.deletePage('aee6734c-17c2-4e60-9506-b5670b95367e');
scope.deletePage(testData.waiverPage.id);

expect(modalMessage.error).toHaveBeenCalledTimes(1);
expect(modalMessage.error.calls.argsFor(0)[0].message).toBe(
Expand All @@ -172,20 +172,18 @@ describe('Controller: eventForm', function () {
it('deletes pages', () => {
spyOn(GrowlService, 'growl');
spyOn(modalMessage, 'confirm').and.returnValue($q.resolve());
scope.conference.registrationPages[1].blocks =
scope.conference.registrationPages[1].blocks.filter(
(block) => block.profileType === null,
);
const page = scope.conference.registrationPages[1];
page.blocks = page.blocks.filter((block) => block.profileType === null);

scope.deletePage('7b4c19df-7377-4d37-90fb-5b262bb66d1a', true);
scope.deletePage(page.id, true);
scope.$digest();

expect(modalMessage.confirm).toHaveBeenCalledTimes(1);
const confirmationMessage =
modalMessage.confirm.calls.argsFor(0)[0].question;

expect(confirmationMessage).toContain(
'Are you sure you want to delete <strong>Page 2</strong>?',
`Are you sure you want to delete <strong>${page.title}</strong>?`,
);

expect(confirmationMessage).toContain(
Expand All @@ -198,7 +196,7 @@ describe('Controller: eventForm', function () {

expect(GrowlService.growl).toHaveBeenCalledTimes(1);
expect(GrowlService.growl.calls.argsFor(0)[3]).toBe(
'Page "Page 2" has been deleted.',
`Page "${page.title}" has been deleted.`,
);
});
});
Expand All @@ -211,7 +209,7 @@ describe('Controller: eventForm', function () {

expect(newBlock.id).not.toBe(existingBlock.id);
expect(newBlock.position).toBe(4);
expect(newBlock.title).toBe('Dropdown Question (copy)');
expect(newBlock.title).toBe(`${existingBlock.title} (copy)`);
expect(newBlock.rules[0].id).not.toBe(existingBlock.rules[0].id);
expect(newBlock.rules[0].blockId).toBe(newBlock.id);
});
Expand Down Expand Up @@ -266,22 +264,24 @@ describe('Controller: eventForm', function () {
});

describe('deleteBlock', () => {
const block = testData.conference.registrationPages[1].blocks[4];

it('deletes a block', () => {
spyOn(GrowlService, 'growl');

scope.deleteBlock('0b876382-5fd1-46af-b778-10fc9b1b530d', true);
scope.deleteBlock(block.id, true);

expect(GrowlService.growl).toHaveBeenCalledTimes(1);
expect(GrowlService.growl.calls.argsFor(0)[3]).toBe(
'"Multiple Choice Question" has been deleted.',
`"${block.title}" has been deleted.`,
);
});

it('refuses to delete a block with dependent rules', () => {
spyOn(modalMessage, 'error');
scope.conference.registrationPages.push(testData.rulesPage);

scope.deleteBlock('0b876382-5fd1-46af-b778-10fc9b1b530d', true);
scope.deleteBlock(block.id, true);

expect(modalMessage.error).toHaveBeenCalledTimes(1);
const errorMessage = modalMessage.error.calls.argsFor(0)[0].message;
Expand Down
34 changes: 20 additions & 14 deletions test/spec/controllers/eventRegistrations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ describe('Controller: eventRegistrations', function () {
describe('toggleColumn', () => {
it('toggles the column visibility', () => {
const setItem = spyOn($window.localStorage, 'setItem');
scope.toggleColumn(0);
const blockIndex = 0;
const block = scope.blocks[blockIndex];
scope.toggleColumn(blockIndex);

expect(scope.blocks[0].visible).toBe(true);
expect(block.visible).toBe(true);
expect(setItem).toHaveBeenCalledWith(
`visibleBlocks:${testData.conference.id}`,
'["e088fefc-eb9c-4904-b849-017facc9e063"]',
`["${block.id}"]`,
);

expect(scope.queryParameters.block).toEqual([
'e088fefc-eb9c-4904-b849-017facc9e063',
]);
expect(scope.queryParameters.block).toEqual([block.id]);

scope.toggleColumn(0);

Expand Down Expand Up @@ -220,21 +220,26 @@ describe('Controller: eventRegistrations', function () {
});

it('returns the value of simple answers', () => {
scope.queryParameters.orderBy = '9b83eebd-b064-4edf-92d0-7982a330272a';
const answer = testData.registration.registrants[0].answers[0];
scope.queryParameters.orderBy = answer.blockId;

expect(scope.answerSort(testData.registration.registrants[0])).toBe('M');
expect(scope.answerSort(testData.registration.registrants[0])).toBe(
answer.value,
);
});

it('returns the values of complex answers', () => {
scope.queryParameters.orderBy = '122a15bf-0608-4813-834a-0d31a8c44c64';
const answer = testData.registration.registrants[0].answers[6];
scope.queryParameters.orderBy = answer.blockId;

expect(scope.answerSort(testData.registration.registrants[0])).toBe(
'Test,Person',
);
});

it('returns the keys of checkbox answers', () => {
scope.queryParameters.orderBy = '18ccfb09-3006-4981-ab5e-405ccf2aad1c';
const answer = testData.registration.registrants[0].answers[4];
scope.queryParameters.orderBy = answer.blockId;

expect(scope.answerSort(testData.registration.registrants[0])).toBe(
'651',
Expand Down Expand Up @@ -543,15 +548,16 @@ describe('Controller: eventRegistrations', function () {
it('deletes a registrant in a group', () => {
$httpBackend.expectDELETE(/^registrants\/.+$/).respond(204, '');

scope.deleteRegistrant(scope.registrants[0]);
const registrant = scope.registrants[0];
scope.deleteRegistrant(registrant);
fakeModal.close();
$httpBackend.flush();

expect(scope.registrations.length).toBe(1);
expect(scope.registrants.length).toBe(1);
expect(scope.registrations[0].registrants.map((r) => r.id)).toEqual([
'c0855056-efc8-4ea7-81aa-4b0902376db1',
]);
expect(scope.registrations[0].registrants.map((r) => r.id)).not.toContain(
registrant.id,
);

expect(scope.registrations[0].groupRegistrants.length).toBe(0);
});
Expand Down
39 changes: 17 additions & 22 deletions test/spec/controllers/reviewRegistration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,25 @@ describe('Controller: ReviewRegistrationCtrl', function () {

describe('currentPayment', () => {
it('should have balance set to the remaining balance', () => {
expect(scope.currentPayment.amount).toBe(49);
expect(scope.currentPayment.amount).toBe(
testData.registration.remainingBalance,
);
});
});

describe('findAnswer', () => {
it('should return an answer', function () {
expect(
scope.findAnswer('9b83eebd-b064-4edf-92d0-7982a330272a').value,
).toBe('M');
it('finds an answer by its block id', function () {
const answer = testData.registration.registrants[0].answers[0];

expect(scope.findAnswer(answer.blockId)).toBe(answer);
});
});

describe('getBlock', () => {
it('finds a block by its id', () => {
expect(scope.getBlock('e088fefc-eb9c-4904-b849-017facc9e063').title).toBe(
'Email',
);
const block = testData.conference.registrationPages[0].blocks[0];

expect(scope.getBlock(block.id)).toBe(block);
});
});

Expand Down Expand Up @@ -130,34 +132,27 @@ describe('Controller: ReviewRegistrationCtrl', function () {
});

describe('isBlockInvalid', () => {
const registrantId = testData.registrants[0].id;
const blockId = 'block-1';

it('returns false when there are no errors', () => {
initController({
validateRegistrant: {
validate: () => [],
},
});

expect(
scope.isBlockInvalid(
'6bd0f946-b010-4ef5-83f0-51c17449baf3',
'e088fefc-eb9c-4904-b849-017facc9e063',
),
).toBe(false);
expect(scope.isBlockInvalid(registrantId, blockId)).toBe(false);
});

it('returns true when there are errors', () => {
initController({
validateRegistrant: {
validate: () => ['e088fefc-eb9c-4904-b849-017facc9e063'],
validate: () => [blockId],
},
});

expect(
scope.isBlockInvalid(
'6bd0f946-b010-4ef5-83f0-51c17449baf3',
'e088fefc-eb9c-4904-b849-017facc9e063',
),
).toBe(true);
expect(scope.isBlockInvalid(registrantId, blockId)).toBe(true);
});
});

Expand All @@ -175,7 +170,7 @@ describe('Controller: ReviewRegistrationCtrl', function () {
it('returns false when there are errors', () => {
initController({
validateRegistrant: {
validate: () => ['e088fefc-eb9c-4904-b849-017facc9e063'],
validate: () => ['block-1'],
},
});

Expand Down

0 comments on commit e60d16d

Please sign in to comment.