Skip to content

Commit

Permalink
MAT 6727 added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-prateekkeerthi committed Mar 18, 2024
1 parent 6bae7ac commit 6b11096
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
26 changes: 26 additions & 0 deletions src/controllers/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {} from 'node-mocks-http';

describe('AppController', () => {
let appController: AppController;
let appService: AppService;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
Expand All @@ -16,6 +17,7 @@ describe('AppController', () => {
}).compile();

appController = app.get<AppController>(AppController);
appService = app.get<AppService>(AppService);
});

describe('root', () => {
Expand All @@ -28,5 +30,29 @@ describe('AppController', () => {
await expect(appController.getFile(response)).toBeDefined();
//expect(res.statusCode).toEqual(200);
});

it('should call generateXlsx method of excelService', async () => {
jest
.spyOn(appService, 'generateXlsx')
.mockResolvedValueOnce(Buffer.from('mocked-excel-data'));
const res: Partial<Response> = {
header: jest.fn(),
send: jest.fn(),
};
await appController.getFile(res as Response);
expect(appService.generateXlsx).toHaveBeenCalledTimes(1);
});
it('should send the generated Excel file as the response', async () => {
const mockedExcelBuffer = Buffer.from('mocked-excel-data');
jest
.spyOn(appService, 'generateXlsx')
.mockResolvedValueOnce(mockedExcelBuffer);
const res: Partial<Response> = {
header: jest.fn(),
send: jest.fn(),
};
await appController.getFile(res as Response);
expect(res.send).toHaveBeenCalledWith(mockedExcelBuffer);
});
});
});
10 changes: 4 additions & 6 deletions src/services/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import * as ExcelJS from 'exceljs';
import {
defaultKeySheetFontStyle,
keySheetColumnsData,
keySheetDescription,
keySheetRowsData,
Expand Down Expand Up @@ -64,9 +65,8 @@ export class AppService {
bottom: { style: 'thin', color: { argb: '000000' } },
};
tableHeadingCell.font = {
...defaultKeySheetFontStyle,
bold: true,
color: { argb: '000000' },
name: 'Arial',
size: 16,
};

Expand All @@ -85,10 +85,8 @@ export class AppService {
headerRow.height = 18;
headerRow.eachCell((cell) => {
cell.font = {
...defaultKeySheetFontStyle,
bold: true,
color: { argb: '000000' },
name: 'Arial',
size: 14,
};
cell.fill = {
type: 'pattern',
Expand All @@ -110,7 +108,7 @@ export class AppService {
dataRows.forEach((row) => {
//row.height = 18;
row.eachCell((cell) => {
cell.font = { color: { argb: '000000' }, name: 'Arial', size: 14 };
cell.font = defaultKeySheetFontStyle;
cell.alignment = { wrapText: true, vertical: 'middle' };
cell.border = {
bottom: { style: 'thin', color: { argb: 'D4D4D4' } },
Expand Down
10 changes: 8 additions & 2 deletions src/services/static/KeySheetData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const keySheetRowsData = [
'CODE: SNOMED-CT 4525004]',
],
[
'Tuple',
'Tuple1',
'{ \n' + 'key1: value1, \n' + 'key2: value2, \n' + '... \n' + '}',
'{ \n' +
' period: Interval: 06/29/2017 8:00 AM - 12/31/2024 11:59 PM, \n' +
Expand All @@ -46,8 +46,14 @@ export const keySheetRowsData = [

export const keySheetColumnsData = [
{ name: 'CQL Type' },
{ name: 'Format1' },
{ name: 'Format' },
{ name: 'Example' },
];

export const keySheetDescription = `NOTE: FALSE(...) indicates a false value. The type of falseness is specified in the parentheses.\nFor example, FALSE([]) indicates falseness due to an empty list.\nCells that are too long will be truncated due to limitations in Excel.`;

export const defaultKeySheetFontStyle = {
color: { argb: '000000' },
name: 'Arial',
size: 14,
};

0 comments on commit 6b11096

Please sign in to comment.