Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
al-rosenthal committed Sep 8, 2023
1 parent 1487bb5 commit 32bf987
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions api/src/repositories/survey-block-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { ApiExecuteSQLError } from '../errors/api-error';
import { getMockDBConnection } from '../__mocks__/db';
import { SurveyBlock, SurveyBlockRepository } from './survey-block-repository';
import { PostSurveyBlock, SurveyBlockRepository } from './survey-block-repository';

chai.use(sinonChai);

Expand Down Expand Up @@ -82,7 +82,7 @@ describe('SurveyBlockRepository', () => {
});

const repo = new SurveyBlockRepository(dbConnection);
const block: SurveyBlock = { survey_block_id: 1, survey_id: 1, name: 'Updated name', description: 'block' };
const block: PostSurveyBlock = { survey_block_id: 1, survey_id: 1, name: 'Updated name', description: 'block' };
const response = await repo.updateSurveyBlock(block);
expect(response.survey_block_id).to.be.eql(1);
expect(response.name).to.be.eql('Updated name');
Expand All @@ -98,7 +98,7 @@ describe('SurveyBlockRepository', () => {
});

const repo = new SurveyBlockRepository(dbConnection);
const block: SurveyBlock = { survey_block_id: null, survey_id: 1, name: 'new', description: 'block' };
const block: PostSurveyBlock = { survey_block_id: null, survey_id: 1, name: 'new', description: 'block' };
try {
await repo.updateSurveyBlock(block);
expect.fail();
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('SurveyBlockRepository', () => {
});
const repo = new SurveyBlockRepository(dbConnection);

const block: SurveyBlock = { survey_block_id: null, survey_id: 1, name: 'new', description: 'block' };
const block: PostSurveyBlock = { survey_block_id: null, survey_id: 1, name: 'new', description: 'block' };
const response = await repo.insertSurveyBlock(block);

expect(response.name).to.be.eql('new');
Expand All @@ -148,7 +148,12 @@ describe('SurveyBlockRepository', () => {
});
const repo = new SurveyBlockRepository(dbConnection);
try {
const block = ({ survey_block_id: null, survey_id: 1, name: null, description: null } as any) as SurveyBlock;
const block = ({
survey_block_id: null,
survey_id: 1,
name: null,
description: null
} as any) as PostSurveyBlock;
await repo.insertSurveyBlock(block);
expect.fail();
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions api/src/services/survey-block-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { QueryResult } from 'pg';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { ApiExecuteSQLError } from '../errors/api-error';
import { SurveyBlock, SurveyBlockRepository } from '../repositories/survey-block-repository';
import { PostSurveyBlock, SurveyBlockRepository } from '../repositories/survey-block-repository';
import { getMockDBConnection } from '../__mocks__/db';
import { SurveyBlockService } from './survey-block-service';

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('SurveyBlockService', () => {
const insertBlock = sinon.stub(SurveyBlockRepository.prototype, 'insertSurveyBlock').resolves();
const updateBlock = sinon.stub(SurveyBlockRepository.prototype, 'updateSurveyBlock').resolves();

const blocks: SurveyBlock[] = [
const blocks: PostSurveyBlock[] = [
{ survey_block_id: null, survey_id: 1, name: 'Old Block', description: 'Updated' },
{ survey_block_id: null, survey_id: 1, name: 'New Block', description: 'block' }
];
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('SurveyBlockService', () => {
const insertBlock = sinon.stub(SurveyBlockRepository.prototype, 'insertSurveyBlock').resolves();
const updateBlock = sinon.stub(SurveyBlockRepository.prototype, 'updateSurveyBlock').resolves();

const blocks: SurveyBlock[] = [
const blocks: PostSurveyBlock[] = [
{ survey_block_id: 10, survey_id: 1, name: 'Old Block', description: 'Updated' },
{ survey_block_id: null, survey_id: 1, name: 'New Block', description: 'block' }
];
Expand Down

0 comments on commit 32bf987

Please sign in to comment.