Skip to content

Commit

Permalink
fxi tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenguc committed Dec 8, 2022
1 parent 986e505 commit 914882d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/subscriptions/subscriptions.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { SubscriptionsService } from './subscriptions.service'

jest.mock('@polkadot/api')
jest.mock('../utils')
jest.mock('../../mongo-indexes', () => ({
main: jest.fn(),
}))

describe('subscriptionsService', () => {
let service: SubscriptionsService
Expand Down
12 changes: 6 additions & 6 deletions src/sync/sync.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Test, TestingModule } from '@nestjs/testing'
import { getRepositoryToken } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { MongoRepository } from 'typeorm'
import { finishedSyncMock, syncingSyncMock } from '../../mocks/sync-mock'
import { EnvModule } from '../env/env.module'
import { Sync } from './entity/sync.entity'
import { SyncService } from './sync.service'

describe('SyncService', () => {
let service: SyncService
let repo: Repository<Sync>
let repo: MongoRepository<Sync>

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -19,7 +19,7 @@ describe('SyncService', () => {
provide: getRepositoryToken(Sync),
useValue: {
findOneBy: jest.fn().mockResolvedValue(finishedSyncMock),
update: jest.fn().mockResolvedValue(syncingSyncMock),
findOneAndUpdate: jest.fn().mockResolvedValue(syncingSyncMock),
create: jest.fn().mockResolvedValue({
save: jest.fn().mockResolvedValue(syncingSyncMock),
}),
Expand All @@ -29,7 +29,7 @@ describe('SyncService', () => {
}).compile()

service = module.get<SyncService>(SyncService)
repo = module.get<Repository<Sync>>(getRepositoryToken(Sync))
repo = module.get<MongoRepository<Sync>>(getRepositoryToken(Sync))
})

it('should be defined', () => {
Expand All @@ -46,7 +46,7 @@ describe('SyncService', () => {
it('should update sync data', async () => {
const newBlock = { lastSynced: 200, status: 'syncing', timestamp: '123' }

const repoSpy = jest.spyOn(repo, 'update')
const repoSpy = jest.spyOn(repo, 'findOneAndUpdate')

await service.updateSync(newBlock)

Expand All @@ -56,7 +56,7 @@ describe('SyncService', () => {

describe('finishSync', () => {
it('should update sync status to "synced"', async () => {
const repoSpy = jest.spyOn(repo, 'update')
const repoSpy = jest.spyOn(repo, 'findOneAndUpdate')

await service.finishSync()
expect(repoSpy).toHaveBeenCalled()
Expand Down

0 comments on commit 914882d

Please sign in to comment.