@telstra/messaging
Version:
Telstra SDK Messaging
59 lines (53 loc) • 2.24 kB
text/typescript
import { format, subDays } from 'date-fns';
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
import { Reports } from '../../../src/classes/index.js';
import { Constants } from '../../shared/Constants.js';
import AUTH_CONFIG from '../../shared/credentials.json' with { type: 'json' };
import { server } from '../../shared/mswServer.js';
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
const reports = new Reports(AUTH_CONFIG);
describe('Reports', () => {
describe('request a messages report', () => {
describe('when the client sends a valid request', () => {
it('should pass', async () => {
const startDate = format(subDays(new Date(), 3), 'yyyy-MM-dd');
const endDate = format(new Date(), 'yyyy-MM-dd');
const data = {
startDate,
endDate,
reportCallbackUrl: 'https://www.example.com',
filter: 'test',
};
await expect(reports.create(data)).resolves.toEqual(Constants.CREATE_MESSAGES_REPORT_RESPONSE);
});
});
});
describe('fetch all reports', () => {
describe('when the client sends a valid request', () => {
it('should pass', async () => {
await expect(reports.getAll()).resolves.toEqual(Constants.GET_ALL_MESSAGES_REPORT_RESPONSE);
});
});
});
// describe("fetch a report", () => {
// describe('when the client sends a valid request', () => {
// it("should pass", async () => {
// await expect(reports.get('6940c774-4335-4d2b-b758-4ecb19412e85')).resolves.toEqual(Constants.GET_MESSAGES_REPORT_RESPONSE);
// });
// });
// describe('when the client sends [virtualNumber] as integer', () => {
// it("should throw an assertion error", async () => {
// const callback = async () => virtualNumber.get(412345678);
// await expect(callback).rejects
// .toThrow(
// new AssertionError({
// errorCode: `MISSING_ATTRIBUTE`,
// errorMessage: `data.virtualNumber should be string`,
// })
// );
// });
// });
// });
});