Skip to content
Merged
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
6 changes: 5 additions & 1 deletion docker/mock/simbrief/xml.fetcher-123456-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@
"sched_out": "1767603600",
"sched_off": "1767604800",
"sched_on": "1767633000",
"sched_in": "1767633900"
"sched_in": "1767633900",
"est_out": "1767603900",
"est_off": "1767604980",
"est_on": "1767633240",
"est_in": "1767633960"
},
"weights": {
"cargo": "8004",
Expand Down
5 changes: 5 additions & 0 deletions features/_context/rest-api.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ApiUserType =
| 'operations with Simbrief ID but non existing aircraft'
| 'operations with Simbrief ID and alternate airport missing from database'
| 'cabin crew'
| 'new cabin crew'
| 'Alan Doe'
| 'Michael Doe';

Expand All @@ -30,6 +31,10 @@ const apiUsers: Record<ApiUserType, { email: string; password: string }> = {
email: 'cabin-crew@example.com',
password: 'P@$$w0rd',
},
'new cabin crew': {
email: 'nina.doe@example.com',
password: 'P@$$w0rd',
},
'operations with valid Simbrief ID': {
email: 'abby.doe@example.com',
password: 'P@$$w0rd',
Expand Down
133 changes: 128 additions & 5 deletions features/flight/management/flight.create-with-simbrief.feature
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,141 @@ Feature: Create a flight with Simbrief
"""
And I set database to initial state

Scenario: As a cabin crew I cannot create a flight
Scenario: As a cabin crew without SimBrief connected I cannot import a flight
Given I am signed in as "cabin crew"
When I send a "POST" request to "/api/v1/flight/create-with-simbrief"
Then the response status should be 403
Then the response status should be 400
And the response body should contain:
"""json
{
"message": "Forbidden resource",
"error": "Forbidden",
"statusCode": 403
"statusCode": 400,
"error": "Bad Request",
"message": "User has not connected SimBrief ID."
}
"""

Scenario: As a cabin crew with SimBrief connected I import my flight and I am checked in with the estimated times of the plan
Given I am signed in as "admin"
When I send a "POST" request to "/api/v1/user" with body:
"""json
{
"name": "Nina Doe",
"email": "nina.doe@example.com",
"password": "P@$$w0rd",
"role": "CabinCrew",
"pilotLicenseId": "UK-54321",
"homeAirportId": "3c721cc6-c653-4fad-be43-dc9d6a149383",
"simbriefUserId": "123456"
}
"""
Then the response status should be 201
Given I am signed in with a new session as "new cabin crew"
When I send a "POST" request to "/api/v1/flight/create-with-simbrief"
Then the response status should be 201
And the response body property "status" should contain:
"""json
"checked_in"
"""
And the response body property "timesheet" should contain:
"""json
{
"scheduled": {
"offBlockTime": "2026-01-05T09:00:00.000Z",
"takeoffTime": "2026-01-05T09:20:00.000Z",
"arrivalTime": "2026-01-05T17:10:00.000Z",
"onBlockTime": "2026-01-05T17:25:00.000Z"
},
"estimated": {
"offBlockTime": "2026-01-05T09:05:00.000Z",
"takeoffTime": "2026-01-05T09:23:00.000Z",
"arrivalTime": "2026-01-05T17:14:00.000Z",
"onBlockTime": "2026-01-05T17:26:00.000Z"
}
}
"""
And the response body property "pilot" should contain:
"""json
{
"id": "@uuid",
"name": "Nina Doe",
"pilotLicenseId": "UK-54321",
"totalFlightTime": 0
}
"""
And I remember the response body property "id" as "flightId"
When I send a "GET" request to "/api/v1/flight/{{flightId}}/events"
Then the response status should be 200
And the response body should contain:
"""json
[
{
"id": "@uuid",
"scope": "user",
"type": "flight.preliminary-loadsheet-updated",
"payload": {},
"actor": {
"id": "@uuid",
"name": "Nina Doe"
},
"createdAt": "@date('within 1 minute from now')"
},
{
"id": "@uuid",
"scope": "user",
"type": "flight.released",
"payload": {},
"actor": {
"id": "@uuid",
"name": "Nina Doe"
},
"createdAt": "@date('within 1 minute from now')"
},
{
"id": "@uuid",
"scope": "user",
"type": "flight.pilot-checked-in",
"payload": {},
"actor": {
"id": "@uuid",
"name": "Nina Doe"
},
"createdAt": "@date('within 1 minute from now')"
}
]
"""
When I send a "PATCH" request to "/api/v1/flight/{{flightId}}/departure-parking-position" with body:
"""json
{ "departureParkingPositionId": "ad5a6ebd-dad8-4400-8bb4-b7cee3b00fa9" }
"""
Then the response status should be 200
When I send a "GET" request to "/api/v1/user/me"
Then the response status should be 200
And the response body property "currentFlightId" should contain:
"""json
"@uuid"
"""
And I set database to initial state

Scenario: As a cabin crew with a flight in progress I cannot import another flight
Given I am signed in as "cabin crew"
When I send a "PATCH" request to "/api/v1/user/me" with body:
"""json
{
"simbriefUserId": "123456"
}
"""
Then the response status should be 200
When I send a "POST" request to "/api/v1/flight/create-with-simbrief"
Then the response status should be 409
And the response body should contain:
"""json
{
"statusCode": 409,
"error": "Conflict",
"message": "A flight is already in progress. Close it before importing another plan."
}
"""
And I set database to initial state

Scenario: As operations user importing a plan for an aircraft not in the fleet I create it unconfirmed
Given I am signed in as "operations with Simbrief ID but non existing aircraft"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,33 +309,33 @@ Feature: Update flight departure parking position
}
"""

Scenario: As operations I cannot update departure parking position after pilot checked in
Scenario: As operations I cannot update departure parking position after boarding started
Given I am signed in as "operations"
When I send a "PATCH" request to "/api/v1/flight/48760636-9520-4863-b32f-f3618556feb7/departure-parking-position" with body:
When I send a "PATCH" request to "/api/v1/flight/7e2b8d5c-a6f3-4049-98b1-d4f9a2e35b67/departure-parking-position" with body:
"""json
{ "departureParkingPositionId": "ad5a6ebd-dad8-4400-8bb4-b7cee3b00fa9" }
{ "departureParkingPositionId": "ae098e8f-b088-41a6-a566-880c7dd5e931" }
"""
Then the response status should be 422
And the response body should contain:
"""json
{
"message": "Cannot update departure parking position, because pilot is already checked in.",
"message": "Cannot update departure parking position, because boarding has started.",
"error": "Unprocessable Content",
"statusCode": 422
}
"""

Scenario: As cabin crew I cannot update departure parking position after pilot checked in
Scenario: As cabin crew I cannot update departure parking position after boarding started
Given I am signed in as "cabin crew"
When I send a "PATCH" request to "/api/v1/flight/48760636-9520-4863-b32f-f3618556feb7/departure-parking-position" with body:
When I send a "PATCH" request to "/api/v1/flight/7e2b8d5c-a6f3-4049-98b1-d4f9a2e35b67/departure-parking-position" with body:
"""json
{ "departureParkingPositionId": "ad5a6ebd-dad8-4400-8bb4-b7cee3b00fa9" }
{ "departureParkingPositionId": "ae098e8f-b088-41a6-a566-880c7dd5e931" }
"""
Then the response status should be 422
And the response body should contain:
"""json
{
"message": "Cannot update departure parking position, because pilot is already checked in.",
"message": "Cannot update departure parking position, because boarding has started.",
"error": "Unprocessable Content",
"statusCode": 422
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flight-tracker-api",
"version": "3.88.0",
"version": "3.89.0",
"private": true,
"homepage": "https://mypreflight.io",
"author": "mypreflight",
Expand Down
4 changes: 4 additions & 0 deletions src/core/provider/simbrief/type/simbrief.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ export type Times = {
sched_off: string;
sched_on: string;
sched_in: string;
est_out?: string | EmptyElement;
est_off?: string | EmptyElement;
est_on?: string | EmptyElement;
est_in?: string | EmptyElement;
};

export type Fuel = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {
AlternateAirportCandidate,
CreateFlightFromSimbriefCommand,
CreateFlightFromSimbriefHandler,
} from './create-flight-from-simbrief.command';
import { AirportType } from '../../../airports/model/airport.model';
import { FlightServiceType } from '../../model/flight.model';
import {
Crew,
OperationalFlightPlan,
Times,
} from '../../../../core/provider/simbrief/type/simbrief.types';
import { Schedule } from '../../model/timesheet.model';
import { PilotHasFlightInProgressError } from '../../model/error/flight.error';
import { GetUserSimbriefIdQuery } from '../../../users/application/query/get-user-simbrief-id.query';
import { CrewMember } from '../../../crew/application/command/assign-crew-to-flight.command';
import { CrewRole } from '../../../crew/model/crew.model';

Expand Down Expand Up @@ -287,3 +292,95 @@ describe('CreateFlightFromSimbriefHandler weight import', () => {
expect(massOf(ofpWithWeights('8004', '8004', '120'))).toBeNull();
});
});

describe('CreateFlightFromSimbriefHandler estimated times', () => {
let handler: CreateFlightFromSimbriefHandler;

function estimate(times: Partial<Times>): Schedule {
return (
handler as unknown as {
estimatedSchedule: (ofp: OperationalFlightPlan) => Schedule;
}
).estimatedSchedule({
times: {
sched_out: '1767603600',
sched_off: '1767604800',
sched_on: '1767633000',
sched_in: '1767633900',
...times,
},
} as OperationalFlightPlan);
}

beforeEach(() => {
handler = buildHandler();
});

it('takes the estimated times of the plan', () => {
expect(
estimate({
est_out: '1767603900',
est_off: '1767604980',
est_on: '1767633240',
est_in: '1767633960',
}),
).toEqual({
offBlockTime: new Date('2026-01-05T09:05:00.000Z'),
takeoffTime: new Date('2026-01-05T09:23:00.000Z'),
arrivalTime: new Date('2026-01-05T17:14:00.000Z'),
onBlockTime: new Date('2026-01-05T17:26:00.000Z'),
});
});

it('falls back to the scheduled time where the plan has no estimate', () => {
expect(estimate({ est_off: '1767604980', est_on: {} })).toEqual({
offBlockTime: new Date('2026-01-05T09:00:00.000Z'),
takeoffTime: new Date('2026-01-05T09:23:00.000Z'),
arrivalTime: new Date('2026-01-05T17:10:00.000Z'),
onBlockTime: new Date('2026-01-05T17:25:00.000Z'),
});
});
});

describe('CreateFlightFromSimbriefHandler pilot import', () => {
const getOperationalFlightPlan = jest.fn();

function buildPilotHandler(
currentFlightId: string | null,
): CreateFlightFromSimbriefHandler {
const queryBus = {
execute: jest.fn((query: unknown) =>
Promise.resolve(
query instanceof GetUserSimbriefIdQuery
? '123456'
: { currentFlightId },
),
),
};

return new CreateFlightFromSimbriefHandler(
queryBus as never,
undefined as never,
{ getOperationalFlightPlan } as never,
undefined as never,
undefined as never,
undefined as never,
undefined as never,
);
}

beforeEach(() => {
getOperationalFlightPlan.mockReset();
});

it('refuses a pilot with a flight in progress before fetching the plan', async () => {
const handler = buildPilotHandler('23952e79-6b38-49ed-a1db-bd4d9b3cedab');

await expect(
handler.execute(
new CreateFlightFromSimbriefCommand('flight-id', 'pilot-id', true),
),
).rejects.toBeInstanceOf(PilotHasFlightInProgressError);
expect(getOperationalFlightPlan).not.toHaveBeenCalled();
});
});
Loading
Loading