Skip to content

Commit

Permalink
feat(WEB-2070): WEB-2070 lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sairam459 committed Apr 8, 2024
1 parent feac2d3 commit 31afac4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/whisp/whisp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class WhispService {
const { timeToLiveSec, expirationDate } = WhispService.fillTTL(whispIn, now);
whisp.timeToLiveSec = timeToLiveSec;
whisp.expirationDate = expirationDate;
const whispInstance = new this.whispModel(whisp);
const WhispDocModel = this.whispModel;
const whispInstance = new WhispDocModel(whisp);
const createdWhisp = await whispInstance.save();
await this.eventService.triggerEvent(new Event(EventNames.WHISP_CREATED, createdWhisp));
this.distributionService.distributeWhisp(createdWhisp);
Expand Down
15 changes: 6 additions & 9 deletions tests/unit/whisp/whisp.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { FileService } from '../../../src/file/file.service';
import { SequenceService } from '../../../src/sequence/sequence.service';
import { WhispService } from '../../../src/whisp/whisp.service';
import { DistributionService } from '../../../src/distribution/distribution.service';
import { Whisp } from '../../../src/whisp/whisp.entity';

jest.mock('../../../src/distribution/distribution.service');
jest.mock('../../../src/event/event.service');
Expand All @@ -25,20 +24,18 @@ describe('WhispService', () => {
new Promise((resolve) => {
resolve(data);
});

describe('create Whisp', () => {
let constructorData = {};
let constructorData:any;
beforeEach(async () => {
constructorData = {}
constructorData = {};
class mockModel {
constructor(public data?: any) {
constructorData = data;
this.data = data

this.data = data;
}

save = jest.fn().mockReturnValue(this.data);
}

const moduleRef = await Test.createTestingModule({
providers: [
{
Expand Down Expand Up @@ -66,15 +63,15 @@ describe('WhispService', () => {
await whispService.create({});

expect(constructorData).toHaveProperty('timestamp');
expect(constructorData['timestamp']).toBeDefined();
expect(constructorData.timestamp).toBeDefined();
});

it('should keep custom timestamp when timestamp is provided', async () => {
const timestamp = new Date();
await whispService.create({ timestamp });

expect(constructorData).toHaveProperty('timestamp');
expect(constructorData['timestamp']).toBe(timestamp);
expect(constructorData.timestamp).toBe(timestamp);
});

it('when ttl is provided expirationDate should be generate and be equal to updated date plus ttl duration', async () => {
Expand Down

0 comments on commit 31afac4

Please sign in to comment.