Skip to content

Commit

Permalink
Tests and minor edit for classes/flight.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ericman314 committed Oct 29, 2018
1 parent 2501c2a commit cec7dbc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/src/classes/flight.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid from "uuid";
import randomWords from "random-words";
export default class Flight {
constructor(params) {
constructor(params = {}) {
this.class = "Flight";
this.id = params.id || uuid.v4();
this.name = params.name || randomWords(3).join("-");
Expand Down
53 changes: 53 additions & 0 deletions server/tests/classes/flight.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Flight from '../../src/classes/flight';
import Simulator from '../../src/classes/simulator';

describe('Flight', () => {

test('should throw if called without the \'new\' operator', () => {
expect(() => { const c = Flight(); }).toThrow(/Cannot call a class as a function/);
});

describe('constructor', () => {
test('should set default parameters', () => {
const f = new Flight();
expect(f.class).toBe('Flight');
expect(f.id).toEqual(expect.stringMatching(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/));
expect(f.name).toBeDefined();
expect(f.date).toBeDefined();
expect(f.running).toBe(false);
expect(f.simulators).toEqual([]);
});
});

describe('addSimulator', () => {
test('should add a simulator', () => {
const f = new Flight();
const s = new Simulator();
f.addSimulator(s);
expect(f.simulators[0]).toBe(s.id);
});
});

describe('removeSimulator', () => {
test('should remove a simulator', () => {
const f = new Flight();
const s = new Simulator();
f.addSimulator(s);
f.removeSimulator(s.id);
expect(f.simulators.length).toBe(0);
});
})

describe('stopFlight, pause, and resume', () => {
test('should stop, pause, or resume a flight', () => {
const f = new Flight({ running: true });
expect(f.running).toBe(true);
f.pause();
expect(f.running).toBe(false);
f.resume();
expect(f.running).toBe(true);
f.stopFlight();
expect(f.running).toBe(false);
});
});
});

0 comments on commit cec7dbc

Please sign in to comment.