@on-time/core
Version:
core business logic for OT API
102 lines (95 loc) • 4.3 kB
JavaScript
const { expect } = require('chai');
const sinon = require('sinon');
const Service = require('../src/Service');
describe('Core Service Tests', () => {
describe('Create Function Tests', () => {
it('should define create function', () => {
const service = new Service(null);
expect(service).to.have.property('create');
});
it('should call injected repository', () => {
const fakeRepository = {create: sinon.spy()};
const service = new Service(fakeRepository);
service.create({});
expect(fakeRepository.create.calledOnce).to.be.true;
});
it('should return result from repository call', async () => {
const fakeRepository = {create: () => ({data: 'fake data'})};
const service = new Service(fakeRepository);
const result = await service.create({});
expect(result).to.eql({data: 'fake data'})
});
});
describe('GetById Function Tests', () => {
it('should define getById function', () => {
const service = new Service(null);
expect(service).to.have.property('getById');
});
it('should call injected repository', () => {
const fakeRepository = { getById: sinon.spy() };
const service = new Service(fakeRepository);
service.getById({});
expect(fakeRepository.getById.calledOnce).to.be.true;
});
it('should return result from repository call', async () => {
const fakeRepository = { getById: () => ({ data: 'fake data' }) };
const service = new Service(fakeRepository);
const result = await service.getById({});
expect(result).to.eql({ data: 'fake data' })
});
});
describe('GetAll Function Tests', () => {
it('should define getAll function', () => {
const service = new Service(null);
expect(service).to.have.property('getAll');
});
it('should call injected repository', () => {
const fakeRepository = { getAll: sinon.spy() };
const service = new Service(fakeRepository);
service.getAll({});
expect(fakeRepository.getAll.calledOnce).to.be.true;
});
it('should return result from repository call', async () => {
const fakeRepository = { getAll: () => ({ data: 'fake data' }) };
const service = new Service(fakeRepository);
const result = await service.getAll({});
expect(result).to.eql({ data: 'fake data' })
});
});
describe('Update Function Tests', () => {
it('should define update function', () => {
const service = new Service(null);
expect(service).to.have.property('update');
});
it('should call injected repository', () => {
const fakeRepository = { update: sinon.spy() };
const service = new Service(fakeRepository);
service.update({});
expect(fakeRepository.update.calledOnce).to.be.true;
});
it('should return result from repository call', async () => {
const fakeRepository = { update: () => ({ data: 'fake data' }) };
const service = new Service(fakeRepository);
const result = await service.update({});
expect(result).to.eql({ data: 'fake data' })
});
});
describe('Update Function Tests', () => {
it('should define delete function', () => {
const service = new Service(null);
expect(service).to.have.property('delete');
});
it('should call injected repository', () => {
const fakeRepository = { delete: sinon.spy() };
const service = new Service(fakeRepository);
service.delete({});
expect(fakeRepository.delete.calledOnce).to.be.true;
});
it('should return result from repository call', async () => {
const fakeRepository = { delete: () => ({ data: 'fake data' }) };
const service = new Service(fakeRepository);
const result = await service.delete({});
expect(result).to.eql({ data: 'fake data' })
});
});
});