Skip to content

Commit

Permalink
add headless tests and promise cover
Browse files Browse the repository at this point in the history
  • Loading branch information
xr0master committed Jan 29, 2024
1 parent 05fd600 commit bbf35ec
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ describe('send method', () => {
expect(error).toBeUndefined();
}
});

it('should call the init and the send method successfully as promise', () => {
emailjs.init({
publicKey: 'C2JWGTestKeySomething',
});

return emailjs.send('default_service', 'my_test_template').then(
(result) => {
expect(result).toEqual({ status: 200, text: 'OK' });
},
(error) => {
expect(error).toBeUndefined();
},
);
});
});

describe('send-form method', () => {
Expand All @@ -43,4 +58,21 @@ describe('send-form method', () => {
expect(error).toBeUndefined();
}
});

it('should call the init and the sendForm method successfully as promise', () => {
const form: HTMLFormElement = document.createElement('form');

emailjs.init({
publicKey: 'C2JWGTestKeySomething',
});

return emailjs.sendForm('default_service', 'my_test_template', form).then(
(result) => {
expect(result).toEqual({ status: 200, text: 'OK' });
},
(error) => {
expect(error).toBeUndefined();
},
);
});
});
55 changes: 55 additions & 0 deletions src/methods/send/send.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,43 @@ describe('sdk v4', () => {
).toThrow('The service ID is required');
});

it('should call the send method and fail on headless', async () => {
try {
const result = await send(
'default_service',
'my_test_template',
{},
{
publicKey: 'C2JWGTestKeySomething',
blockHeadless: true,
},
);
expect(result).toBeUndefined();
} catch (error) {
expect(error).toEqual({
status: 451,
text: 'Unavailable For Headless Browser',
});
}
});

it('should call the send method and fail on headless as promise', () => {
return send('', 'my_test_template', undefined, {
publicKey: 'C2JWGTestKeySomething',
blockHeadless: true,
}).then(
(result) => {
expect(result).toBeUndefined();
},
(error) => {
expect(error).toEqual({
status: 451,
text: 'Unavailable For Headless Browser',
});
},
);
});

it('should call the send method and fail on the template ID', () => {
expect(() =>
send('default_service', '', undefined, {
Expand All @@ -78,4 +115,22 @@ describe('sdk v4', () => {
expect(error).toBeUndefined();
}
});

it('should call the send method as promise', () => {
return send(
'default_service',
'my_test_template',
{},
{
publicKey: 'C2JWGTestKeySomething',
},
).then(
(result) => {
expect(result).toEqual({ status: 200, text: 'OK' });
},
(error) => {
expect(error).toBeUndefined();
},
);
});
});
51 changes: 51 additions & 0 deletions src/methods/sendForm/sendForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@ describe('sdk v4', () => {
).toThrow('The template ID is required');
});

it('should call the sendForm and fail on headless', async () => {
const form: HTMLFormElement = document.createElement('form');

try {
const result = await sendForm('default_service', 'my_test_template', form, {
publicKey: 'C2JWGTestKeySomething',
blockHeadless: true,
});
expect(result).toBeUndefined();
} catch (error) {
expect(error).toEqual({
status: 451,
text: 'Unavailable For Headless Browser',
});
}
});

it('should call the sendForm and fail on headless as promise', () => {
const form: HTMLFormElement = document.createElement('form');

return sendForm('default_service', 'my_test_template', form, {
publicKey: 'C2JWGTestKeySomething',
blockHeadless: true,
}).then(
(result) => {
expect(result).toBeUndefined();
},
(error) => {
expect(error).toEqual({
status: 451,
text: 'Unavailable For Headless Browser',
});
},
);
});

it('should call the sendForm with id selector', async () => {
const form: HTMLFormElement = document.createElement('form');
form.id = 'form-id';
Expand Down Expand Up @@ -117,4 +153,19 @@ describe('sdk v4', () => {
expect(error).toBeUndefined();
}
});

it('should call the sendForm with form element as promise', () => {
const form: HTMLFormElement = document.createElement('form');

return sendForm('default_service', 'my_test_template', form, {
publicKey: 'C2JWGTestKeySomething',
}).then(
(result) => {
expect(result).toEqual({ status: 200, text: 'OK' });
},
(error) => {
expect(error).toBeUndefined();
},
);
});
});

0 comments on commit bbf35ec

Please sign in to comment.