Skip to content

Commit

Permalink
chore(test): change test order
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Dec 29, 2023
1 parent 8ea5694 commit ba23167
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert, describe, it } from 'vitest';
import { calculateCoefficients } from '../src/helpers/calculateCoefficients.js';
import { calculateCoefficients } from './calculateCoefficients.js';

describe('calculateCoefficients', () => {
it('should calculate coefficients', () => {
Expand Down
77 changes: 77 additions & 0 deletions apps/queue/src/integration/ses.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import assert from 'node:assert';
import { MAILER_CONFIG } from '@next/constants';
import { afterEach, beforeEach, describe, it, vi } from 'vitest';
import { sesSendEmail } from './ses.js';

// TODO: write tests for the email send
describe('integration.ses', () => {
let stub: any;
vi.mock('aws-sdk/client-ses', () => ({
SESClient: vi.fn(() => ({
send: vi.fn().mockResolvedValue({}),
destroy: vi.fn(),
})),
SendTemplatedEmailCommand: vi.fn(),
}));

vi.mock('@/config/config.js', () => ({
Config: {
AWS_REGION: 'your-region',
AWS_ACCESS_KEY_ID: 'your-access-key-id',
AWS_SECRET_ACCESS_KEY: 'your-secret-access-key',
},
}));

beforeEach(() => {
// stub = sinon.stub(ofetch, 'post');
});

afterEach(() => {
vi.clearAllMocks();
// stub.restore();
});

it.skip('send a email to a single recipient', async () => {
const email = {
recipient: '[email protected]',
body: {
name: 'My name',
},
};

const sender = { name: 'test', email: '[email protected]' };

await sesSendEmail(email, sender, 'templateId');
assert.equal(stub.callCount, 1);
assert.equal(
stub.firstCall.args[0],
'https://api.sendgrid.com/v3/mail/send',
);
const params = stub.firstCall.args[1];
assert.equal(params.personalizations.length, 1);
assert.equal(params.from.name, sender.name);
assert.equal(params.from.email, MAILER_CONFIG.EMAIL);
assert.equal(params.reply_to.email, sender.email);
});

it.skip('send a email for multiple single recipient', async () => {
const email = [
{
recipient: '[email protected]',
body: { name: 'My name' },
},
{
recipient: '[email protected]',
},
];

await sesSendEmail(email, {}, 'templateId');
assert.deepEqual(stub.callCount, 1);
assert.deepEqual(
stub.firstCall.args[0],
'https://api.sendgrid.com/v3/mail/send',
);
const params = stub.firstCall.args[1];
assert.deepEqual(params.personalizations.length, 2);
});
});

0 comments on commit ba23167

Please sign in to comment.