Skip to content

Commit

Permalink
add tests and commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophiahooley committed Feb 8, 2024
1 parent 7628686 commit 08a0a51
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 6 deletions.
1 change: 0 additions & 1 deletion .nyc_output/26ebb75a-bcc7-4f51-86e7-1546eecf58e3.json

This file was deleted.

1 change: 1 addition & 0 deletions .nyc_output/cadeadf8-7761-4e44-a063-1634f6be9970.json

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":"cadeadf8-7761-4e44-a063-1634f6be9970","pid":24355,"argv":["/usr/local/bin/node","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/node_modules/thread-stream/lib/worker.js"],"execArgv":[],"cwd":"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend","time":1707352736671,"ppid":24354,"coverageFilename":"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/.nyc_output/6a421667-fa0b-4eee-96d4-95c2627ed526.json","externalId":"","uuid":"6a421667-fa0b-4eee-96d4-95c2627ed526","files":[]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":null,"pid":24355,"argv":["/usr/local/bin/node","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/node_modules/.bin/mocha","-r","dotenv/config","--timeout","20000","--exit","-r","ts-node/register","src/tests/Examples.tests.ts","src/tests/Passenger.tests.ts","src/tests/Trimming.tests.ts","src/tests/User.tests.ts"],"execArgv":[],"cwd":"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend","time":1707352734603,"ppid":24354,"coverageFilename":"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/.nyc_output/cadeadf8-7761-4e44-a063-1634f6be9970.json","externalId":"","uuid":"cadeadf8-7761-4e44-a063-1634f6be9970","files":["/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Examples.tests.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/config/server.config.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/routes/routes.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/Passenger.controller.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/data/test-data.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/data/constants.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/util/logger.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/util/trim.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/FlightRequest.controller.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/queryParameterExample.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/pathParameterExample.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/bodyParameterExample.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/retrievePassengers.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/User.controller.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Passenger.tests.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Trimming.tests.ts","/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/User.tests.ts"]}

This file was deleted.

2 changes: 1 addition & 1 deletion .nyc_output/processinfo/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"processes":{"26ebb75a-bcc7-4f51-86e7-1546eecf58e3":{"parent":null,"children":["cef9e676-5d26-489f-a7fe-42f784933324"]},"cef9e676-5d26-489f-a7fe-42f784933324":{"parent":"26ebb75a-bcc7-4f51-86e7-1546eecf58e3","children":[]}},"files":{"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Examples.tests.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/config/server.config.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/routes/routes.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/Passenger.controller.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/data/test-data.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/data/constants.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/util/logger.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/util/trim.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/FlightRequest.controller.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/queryParameterExample.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/pathParameterExample.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/bodyParameterExample.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/retrievePassengers.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/User.controller.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Passenger.tests.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Trimming.tests.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/User.tests.ts":["26ebb75a-bcc7-4f51-86e7-1546eecf58e3"]},"externalIds":{}}
{"processes":{"6a421667-fa0b-4eee-96d4-95c2627ed526":{"parent":"cadeadf8-7761-4e44-a063-1634f6be9970","children":[]},"cadeadf8-7761-4e44-a063-1634f6be9970":{"parent":null,"children":["6a421667-fa0b-4eee-96d4-95c2627ed526"]}},"files":{"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Examples.tests.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/config/server.config.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/routes/routes.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/Passenger.controller.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/data/test-data.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/data/constants.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/util/logger.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/util/trim.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/FlightRequest.controller.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/queryParameterExample.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/pathParameterExample.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/bodyParameterExample.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/TestControllers/retrievePassengers.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/controllers/User.controller.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Passenger.tests.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/Trimming.tests.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"],"/Users/sophiascomputer/Documents/vanderbilt/changeplusplus/MFbackend/miracleflightsbackend/src/tests/User.tests.ts":["cadeadf8-7761-4e44-a063-1634f6be9970"]},"externalIds":{}}
6 changes: 4 additions & 2 deletions src/controllers/Passenger.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type { Request, Response } from 'express';
*/
export const getAllPassengersForUser = async (req: Request, res: Response) => {
// get the userId from the query parameters
// const { userId } = req.query;

const { id } = req.query;

Expand All @@ -37,26 +36,29 @@ export const getAllPassengersForUser = async (req: Request, res: Response) => {
}).base('appwPsfAb6U8CV3mf');

try {
// make a call to AirTable to get all passengers for the user
await base('Passengers').find(
id.toString(),
async function (err: any, record: any | undefined) {
if (err) {
logger.error(err);
return;
} else {
// get related passengers information
const accompPassengers = [] as Record<FieldSet>[];
const accompanyingPassengersPromise = record._rawJson.fields[
'Related Accompanying Passenger(s)'
].map(async (id: string) => {
const passenger = await base('Passengers').find(id.toString());
accompPassengers.push(passenger);
});
// Remove any unnecessary data from the passengers
await Promise.all(accompanyingPassengersPromise);
const trimmedPassengers = accompPassengers.map(
(passenger: Record<FieldSet>) =>
trimPassenger(passenger._rawJson as unknown as PassengerData)
);
res.send(trimmedPassengers);
return res.send(trimmedPassengers);
}
}
);
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/passenger/trimmed-passenger.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface TrimmedPassenger {
'Last Name': string;
'Date of Birth': string;
Gender: string;
Relationship?;
string;
Street: string;
Country: string;
Email: string;
Expand Down
22 changes: 22 additions & 0 deletions src/tests/Passenger.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,26 @@ describe('GET /passenger', () => {
done();
});
});
it('should be an accompanying passenger', done => {
chai
.request(app)
.get('/passenger')
.query({ id: 'recleNlsBm3dheZHy' })
.end((err, res) => {
expect(res.body[1]['Gender']).to.equal('Male');
expect(res).to.have.status(200);
done();
});
});
it('should be an accompanying passenger', done => {
chai
.request(app)
.get('/passenger')
.query({ id: 'recleNlsBm3dheZHy' })
.end((err, res) => {
expect(res.body[2]['Relationship']).to.equal('Father');
expect(res).to.have.status(200);
done();
});
});
});
2 changes: 2 additions & 0 deletions src/util/trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const trimPassenger = (passenger: PassengerData): TrimmedPassenger => {
id: id,
createdTime: createdTime,
Type: Type,
Relationship: fields['Relationship'],
'First Name': fields['First Name'],
'Last Name': fields['Last Name'],
'Date of Birth': fields['Date of Birth'],
Expand All @@ -37,6 +38,7 @@ export const trimPassenger = (passenger: PassengerData): TrimmedPassenger => {
'Full Name': fields['Full Name'],
Age: Age,
'Latest Trip': fields['Latest Trip'],
string: undefined,
};

return trimmedPassenger;
Expand Down

0 comments on commit 08a0a51

Please sign in to comment.