Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion src/app/core/services/geolocation.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,69 @@ describe('GeolocationService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: GeolocationService = TestBed.get(GeolocationService);
const service: GeolocationService = TestBed.inject(GeolocationService);
expect(service).toBeTruthy();
});
});

fdescribe('getPosition', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('method should be defined', () => {
const service: GeolocationService = TestBed.inject(GeolocationService);

expect(service.getPosition()).toBeDefined();
});
});

fdescribe('getPosition', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be called', () => {
const geolocation = new GeolocationService();
spyOn(geolocation, 'getPosition');
geolocation.getPosition();
expect(geolocation.getPosition).toHaveBeenCalled();
});
});

describe('watchPosition with default options', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be the same as getPosition', async (done) => {
const service: GeolocationService = TestBed.inject(GeolocationService);

service.watchPosition().subscribe(x => {
service.getPosition().subscribe(y => {
expect(x).toEqual(y);
done();
});
});
});
});

describe('private method isCachedPositionValid', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be defined', () => {
const geolocation = new GeolocationService();
const spyIsCachedPositionValid = spyOn<any>(geolocation, 'isCachedPositionValid');
expect(spyIsCachedPositionValid).toBeDefined();
});
});

describe('isCachedPositionValid', () => {
let geolocation;
beforeEach(() => TestBed.configureTestingModule({}));

beforeEach(() => {
geolocation = new GeolocationService();
spyOn<any>(geolocation, 'isCachedPositionValid').and.callThrough();
geolocation.getPosition();
});

it('should be called in getPosition', () => {
expect(geolocation.isCachedPositionValid).toHaveBeenCalled();
});
});

54 changes: 52 additions & 2 deletions src/app/core/services/photo.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
import { TestBed } from '@angular/core/testing';
import { PhotoService } from './photo.service';

describe('PhotoService', () => {
fdescribe('PhotoService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: PhotoService = TestBed.get(PhotoService);
const service: PhotoService = TestBed.inject(PhotoService);
expect(service).toBeTruthy();
});
});

fdescribe('getCameraPhoto', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be be defined', () => {
const newPhoto = new PhotoService();
const spyGetCameraPhoto = spyOn<any>(newPhoto, 'getCameraPhoto');
expect(spyGetCameraPhoto).toBeDefined();
});
});

fdescribe('getCameraPhoto', () => {

let photo;

beforeEach(() => TestBed.configureTestingModule({}));

beforeEach(() => {
photo = new PhotoService();
spyOn<any>(photo, 'getCameraPhoto').and.callThrough();
photo.create();
});

it('should be have been called in create method', () => {
expect(photo.getCameraPhoto).toHaveBeenCalled();
});
});

fdescribe('create()', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be defined', () => {
const newPhoto = new PhotoService();
const spyCreate = spyOn(newPhoto, 'create');
expect(spyCreate).toBeDefined();
});
});

fdescribe('create()', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be called', async () => {
const newPhoto = new PhotoService();
spyOn(newPhoto, 'create');
newPhoto.create();
expect(newPhoto.create).toHaveBeenCalled();
});
});


33 changes: 30 additions & 3 deletions src/app/core/services/preset.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import { TestBed } from '@angular/core/testing';
import { Record } from '../classes/record';

import { PresetService } from './preset.service';
import { PresetService, RecordPreset } from './preset.service';

describe('PresetService', () => {
fdescribe('PresetService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: PresetService = TestBed.get(PresetService);
const service: PresetService = TestBed.inject(PresetService);
expect(service).toBeTruthy();
});
});

fdescribe('initRecordWithPreset with commonCold', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should initialize record with preset', () => {
const service: PresetService = TestBed.inject(PresetService);

const record = new Record(20190619);
const result = service.initRecordWithPreset(record, RecordPreset.COMMON_COLD);
expect(result.timestamp).toEqual(20190619);
expect(result.templateName).toEqual('commonCold');
});
});

fdescribe('initRecordWithPreset with heartfailure', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should initialize record with preset', () => {
const service: PresetService = TestBed.inject(PresetService);

const record = new Record(20201208);
const result = service.initRecordWithPreset(record, RecordPreset.HEART_FAILURE);
expect(result.timestamp).toEqual(20201208);
expect(result.templateName).toEqual('heartFailure');
});
});
48 changes: 47 additions & 1 deletion src/app/core/services/proof.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
import { TestBed } from '@angular/core/testing';
import { of } from 'rxjs';

import { ProofService } from './proof.service';
import { GeolocationService } from './geolocation.service';

describe('ProofService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: ProofService = TestBed.get(ProofService);
const service: ProofService = TestBed.inject(ProofService);
expect(service).toBeTruthy();
});
});

fdescribe('private method getLocationProof', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be defined', () => {
const spyGetLocationProof = spyOn<any>(ProofService.prototype, 'getLocationProof');

expect(spyGetLocationProof).toBeDefined();
});
});

fdescribe('createProofWithoutLocation()', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should return proof', () => {
const service: ProofService = TestBed.inject(ProofService);
expect(service.createProofWithoutLocation().timestamp).toEqual(Date.now());
});
});

fdescribe('createProof()', () => {

let mockGeolocationService;

beforeEach(() => {
mockGeolocationService = jasmine.createSpyObj(['getPosition']);
mockGeolocationService.getPosition.and.returnValue(of({coords: {latitude: 123, longitude: 123, accuracy: 123}}));
});

beforeEach(() => TestBed.configureTestingModule({
providers: [{ provide: GeolocationService, useValue: mockGeolocationService }],
}));

it('should return proof', (done: DoneFn) => {
const service: ProofService = TestBed.inject(ProofService);

service.createProof().subscribe(x => {
expect(x.location.longitude).toEqual(123);
expect(x.location.latitude).toEqual(123);
expect(x.location.accuracy).toEqual(123);
done();
});
});
});
88 changes: 86 additions & 2 deletions src/app/core/services/record.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,96 @@
import { TestBed } from '@angular/core/testing';

import { RecordService } from './record.service';
import { Record } from '@core/classes/record';
import { Plugins } from '@capacitor/core';
import { GeolocationService } from './geolocation.service';
import { RecordPreset } from './preset.service';

describe('RecordService', () => {
const { Storage } = Plugins;

fdescribe('RecordService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: RecordService = TestBed.get(RecordService);
const service: RecordService = TestBed.inject(RecordService);
expect(service).toBeTruthy();
});
});

fdescribe('save', () => {
let originalTimeOut;
beforeEach(() => {
originalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000;
});

beforeEach(() => TestBed.configureTestingModule({}));

it('should save', async (done) => {
const service: RecordService = TestBed.inject(RecordService);

const record = new Record(20200730);

service.save(record).subscribe(x => {
expect(JSON.stringify(x[x.length - 1])).toEqual(JSON.stringify(record));
done();
});
await Storage.clear();
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeOut;
});
});

fdescribe('attachProof method attached location proof', () => {
let originalTimeOut;
beforeEach(() => {
originalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000000;
});

beforeEach(() => TestBed.configureTestingModule({}));

it('should attach proof', async (done) => {
const service: RecordService = TestBed.inject(RecordService);

const record = new Record(20200731);

service.attachProof(record).subscribe(x => {
GeolocationService.prototype.getPosition().subscribe(y => {

expect(x.proof.location.accuracy).toEqual(y.coords.accuracy);
expect(x.proof.location.latitude).toEqual(y.coords.latitude);
expect(x.proof.location.longitude).toEqual(y.coords.longitude);
done();
});
});
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeOut;
});
});

fdescribe('create method with commonCold template', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should create commonCold template', () => {
const service: RecordService = TestBed.inject(RecordService);

service.create(RecordPreset.COMMON_COLD).subscribe(x => {
expect(x.templateName).toEqual('commonCold');
});
});
});

fdescribe('create method with heartFailure template', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should create heartFailure template', () => {
const service: RecordService = TestBed.inject(RecordService);

service.create(RecordPreset.HEART_FAILURE).subscribe(x => {
expect(x.templateName).toEqual('heartFailure');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('RecordRepositoryService', () => {
});
});

fdescribe('save()', () => {
describe('save()', () => {
let originalTimeOut;

beforeEach(() => {
Expand Down Expand Up @@ -49,7 +49,7 @@ fdescribe('save()', () => {
});
});

fdescribe('save()', () => {
describe('save()', () => {

beforeEach(() => TestBed.configureTestingModule({}));

Expand All @@ -61,7 +61,7 @@ fdescribe('save()', () => {
});


fdescribe('getJsonAll()', () => {
describe('getJsonAll()', () => {
let originalTimeOut;

beforeEach(() => {
Expand Down Expand Up @@ -89,7 +89,7 @@ fdescribe('getJsonAll()', () => {
});
});

fdescribe('getAll()', () => {
describe('getAll()', () => {
let originalTimeOut;

beforeEach(() => {
Expand Down Expand Up @@ -118,7 +118,7 @@ fdescribe('getAll()', () => {
});
});

fdescribe('get()', () => {
describe('get()', () => {
let originalTimeOut;

beforeEach(() => {
Expand Down Expand Up @@ -153,7 +153,7 @@ fdescribe('get()', () => {
});
});

fdescribe('getJson()', () => {
describe('getJson()', () => {
beforeEach(() => TestBed.configureTestingModule({}));

afterEach(async () => await Storage.clear());
Expand Down
Loading