Skip to content

Commit

Permalink
Remove class exports for all models
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasGLund99 committed Nov 6, 2024
1 parent 87a9236 commit 704ffad
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 63 deletions.
88 changes: 81 additions & 7 deletions src/__tests__/ClientHandler.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import GRPCClientHandler from '../implementations/GRPCClientHandler'
import { AISServiceClientImpl, VesselInfoResponse } from '../../proto/AIS-protobuf/ais'
import { AISServiceClientImpl, VesselInfoResponse, VesselPathResponse } from '../../proto/AIS-protobuf/ais'
import { IDetailedVessel } from '../models/detailedVessel'
import { IVesselPath } from '../models/vesselPath'

// Create a mock implementation of Rpc
// Create a mock implementation of AISServiceClientImpl
const mockClient: jest.Mocked<AISServiceClientImpl> = {
GetVesselInfo: jest.fn(),
} as unknown as jest.Mocked<AISServiceClientImpl>

jest.mock('../../proto/AIS-protobuf/ais')

describe('GRPCClientHandler', () => {
let clientHandler: GRPCClientHandler
let clientHandler: GRPCClientHandler

beforeEach(() => {
clientHandler = new GRPCClientHandler(mockClient)
})
// Setup: runs before each test
beforeEach(() => {
clientHandler = new GRPCClientHandler(mockClient)
})

// Cleanup: runs after each test to reset mocks

describe('GRPCClientHandler - getVesselInfo', () => {
afterEach(() => {
jest.clearAllMocks()
})
it('should return detailed vessel information', async () => {
const mockResponse = { mmsi: 123456789, name: 'Test Vessel', shipType: 'Cargo' } as VesselInfoResponse // Mock the actual response
mockClient.GetVesselInfo.mockResolvedValue(mockResponse)
Expand All @@ -32,3 +40,69 @@ describe('GRPCClientHandler', () => {
})
})
})

describe('GRPCClientHandler - converters', () => {
it('should convert grpcVessel to DetailedVessel', () => {
const grpcVessel: VesselInfoResponse = {
mmsi: 123456789,
name: 'Tom Cruise',
shipType: 'Fighter',
imo: 123,
callSign: 'maverick',
width: 12,
length: 13,
positionFixingDevice: 'gps',
}

const privateMethodProto = Object.getPrototypeOf(clientHandler) //to test private method this is necessary https://stackoverflow.com/questions/48906484/how-to-unit-test-private-methods-in-typescript
const res = privateMethodProto.convertToDetailedVessel(grpcVessel)

expect(res).toEqual<IDetailedVessel>({
mmsi: 123456789,
name: 'Tom Cruise',
shipType: 'Fighter',
imo: 123,
callSign: 'maverick',
width: 12,
length: 13,
positionFixingDevice: 'gps',
})
})

it('should convert grpcVesselPath to VesselPath', () => {
const grpcVesselPath: VesselPathResponse = {
mmsi: 123456789,
pathHistory: {
locations: [
{
point: { lon: 12, lat: 13 },
heading: 90,
timestamp: new Date('2024-01-01T00:00:00Z').getTime(),
},
],
},
pathForecast: {
locations: [],
},
}

const privateMethodProto = Object.getPrototypeOf(clientHandler) //to test private method this is necessary https://stackoverflow.com/questions/48906484/how-to-unit-test-private-methods-in-typescript
const res = privateMethodProto.convertToVesselPath(grpcVesselPath)

expect(res).toEqual<IVesselPath>({
mmsi: 123456789,
pathHistory: {
locations: [
{
point: { lon: 12, lat: 13 },
heading: 90,
timestamp: new Date('2024-01-01T00:00:00Z'),
},
],
},
pathForecast: {
locations: [],
},
})
})
})
13 changes: 0 additions & 13 deletions src/models/detailedVessel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,3 @@ export interface IDetailedVessel {
length?: number
positionFixingDevice?: string
}

export default class DetailedVessel implements IDetailedVessel {
constructor(
public mmsi: number,
public name?: string,
public shipType?: string,
public imo?: number,
public callSign?: string,
public width?: number,
public length?: number,
public positionFixingDevice?: string
) {}
}
8 changes: 0 additions & 8 deletions src/models/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ export interface ILocation {
heading?: number
timestamp: Date
}

export default class Location implements ILocation {
constructor(
public point: IPoint,
public heading: number,
public timestamp: Date
) {}
}
8 changes: 0 additions & 8 deletions src/models/monitoredVessel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@ export interface IMonitoredVessel {
trustworthiness: number
reason?: string
}

export default class MonitoredVessel implements IMonitoredVessel {
constructor(
public mmsi: number,
public trustworthiness: number,
public reason?: string
) {}
}
7 changes: 0 additions & 7 deletions src/models/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,3 @@ export interface IPoint {
lat: number
lon: number
}

export default class Point implements IPoint {
constructor(
public lat: number,
public lon: number
) {}
}
4 changes: 0 additions & 4 deletions src/models/selectionArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ import { IPoint } from './point'
export interface ISelectionArea {
points: IPoint[]
}

export default class SelectionArea implements ISelectionArea {
constructor(public points: IPoint[]) {}
}
8 changes: 0 additions & 8 deletions src/models/simpleVessel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ export interface ISimpleVessel {
heading?: number
mmsi: number
}

export default class SimpleVessel implements ISimpleVessel {
constructor(
public location: ILocation,
public mmsi: number,
public heading?: number
) {}
}
8 changes: 0 additions & 8 deletions src/models/vesselPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,3 @@ export interface IVesselPath {
pathForecast: IPath
pathHistory: IPath
}

export default class VesselPath implements IVesselPath {
constructor(
public mmsi: number,
public pathForecast: IPath,
public pathHistory: IPath
) {}
}

0 comments on commit 704ffad

Please sign in to comment.