Skip to content

Commit

Permalink
Remove old telemetry-service.ts
Browse files Browse the repository at this point in the history
Add/fix telemetry api tests.
  • Loading branch information
NickPhura committed Nov 19, 2024
1 parent 566e991 commit fa39c9f
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 202 deletions.
34 changes: 21 additions & 13 deletions api/src/paths/telemetry/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import sinonChai from 'sinon-chai';
import { SYSTEM_ROLE } from '../../constants/roles';
import * as db from '../../database/db';
import { HTTPError } from '../../errors/http-error';
import {
Telemetry,
TelemetryVendorEnum
} from '../../repositories/telemetry-repositories/telemetry-vendor-repository.interface';
import { SystemUser } from '../../repositories/user-repository';
import { FindTelemetryResponse, TelemetryService } from '../../services/telemetry-service';
import { TelemetryVendorService } from '../../services/telemetry-services/telemetry-vendor-service';
import { KeycloakUserInformation } from '../../utils/keycloak-utils';
import { getMockDBConnection, getRequestHandlerMocks } from '../../__mocks__/db';
import { findTelemetry } from './index';
Expand All @@ -19,19 +23,18 @@ describe('findTelemetry', () => {
});

it('finds and returns telemetry', async () => {
const mockFindTelemetryResponse: FindTelemetryResponse[] = [
const mockFindTelemetryResponse: Telemetry[] = [
{
telemetry_id: '789-789-789',
deployment_id: 2,
critter_id: 3,
acquisition_date: '2021-01-01',
vendor: TelemetryVendorEnum.MANUAL,
serial: '123',
latitude: 49.123,
longitude: -126.123,
telemetry_type: 'vendor',
device_id: 123,
bctw_deployment_id: '123-123-123',
critter_id: 1,
deployment_id: 2,
critterbase_critter_id: '456-456-456',
animal_id: '678-678-678'
elevation: null,
temperature: null
}
];

Expand All @@ -45,14 +48,17 @@ describe('findTelemetry', () => {
sinon.stub(db, 'getDBConnection').returns(mockDBConnection);

const findTelemetryStub = sinon
.stub(TelemetryService.prototype, 'findTelemetry')
.stub(TelemetryVendorService.prototype, 'findTelemetry')
.resolves(mockFindTelemetryResponse);

const findTelemetryCountStub = sinon.stub(TelemetryVendorService.prototype, 'findTelemetryCount').resolves(1);

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.query = {
keyword: 'keyword',
itis_tsns: ['123456'],
start_date: '2021-01-01',
end_date: '2021-02-01',
system_user_id: '11',
page: '2',
limit: '10',
Expand All @@ -72,6 +78,7 @@ describe('findTelemetry', () => {
expect(mockDBConnection.commit).to.have.been.calledOnce;

expect(findTelemetryStub).to.have.been.calledOnceWith(true, 20, sinon.match.object, sinon.match.object);
expect(findTelemetryCountStub).to.have.been.calledOnceWith(true, 20, sinon.match.object);

expect(mockRes.jsonValue.telemetry).to.eql(mockFindTelemetryResponse);
expect(mockRes.jsonValue.pagination).not.to.be.null;
Expand All @@ -91,14 +98,15 @@ describe('findTelemetry', () => {
sinon.stub(db, 'getDBConnection').returns(mockDBConnection);

const findTelemetryStub = sinon
.stub(TelemetryService.prototype, 'findTelemetry')
.stub(TelemetryVendorService.prototype, 'findTelemetry')
.rejects(new Error('a test error'));

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.query = {
keyword: 'keyword',
itis_tsns: ['123456'],
start_date: '2021-01-01',
end_date: '2021-02-01',
system_user_id: '11',
page: '2',
limit: '10',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Readable } from 'stream';
import { IDBConnection } from '../../../database/db';
import { getLogger } from '../../../utils/logger';
import { DBService } from '../../db-service';
import { TelemetryService } from '../../telemetry-service';
import { TelemetryVendorService } from '../../telemetry-services/telemetry-vendor-service';
import { ExportDataStreamOptions, ExportStrategy, ExportStrategyConfig } from '../export-strategy';

const defaultLog = getLogger('services/export-telemetry-strategy');
Expand Down Expand Up @@ -63,7 +63,7 @@ export class ExportTelemetryStrategy extends DBService implements ExportStrategy
* @memberof ExportTelemetryStrategy
*/
_getStream = (_options: ExportDataStreamOptions): Readable => {
const telemetryService = new TelemetryService(this.connection);
const telemetryVendorService = new TelemetryVendorService(this.connection);

Check warning on line 66 in api/src/services/export-services/telemetry/export-telemetry-strategy.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/export-services/telemetry/export-telemetry-strategy.ts#L66

Added line #L66 was not covered by tests

const isUserAdmin = this.config.isUserAdmin;
const systemUserId = this.connection.systemUserId();
Expand All @@ -74,7 +74,7 @@ export class ExportTelemetryStrategy extends DBService implements ExportStrategy
const stream = new Readable({
objectMode: true,
read() {
telemetryService
telemetryVendorService

Check warning on line 77 in api/src/services/export-services/telemetry/export-telemetry-strategy.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/export-services/telemetry/export-telemetry-strategy.ts#L77

Added line #L77 was not covered by tests
.findTelemetry(isUserAdmin, systemUserId, filterFields)
.then((telemetry) => {
for (const item of telemetry) {
Expand Down
185 changes: 0 additions & 185 deletions api/src/services/telemetry-service.ts

This file was deleted.

Loading

0 comments on commit fa39c9f

Please sign in to comment.