Skip to content

Commit

Permalink
Merge pull request #187 from n8rzz/bugfix/ATC-185
Browse files Browse the repository at this point in the history
bugfix/ATC-185
  • Loading branch information
n8rzz authored Dec 13, 2016
2 parents ea02be4 + cfad8d4 commit 57aacc3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
### Bugfixes
- Moves `_comment` blocks in airport json file to be within object the are describing [#145](https://github.com/n8rzz/atc/issues/145)
- Streamlines flight number generation and adds new method to add new callsigns to the existing list [#151](https://github.com/n8rzz/atc/issues/151)
- Adds `_isNumber` check instead of `!magneticNorth` inside `PositionModel.calculatePosition()` and the `AirspaceModel` constructor. [#182](https://github.com/n8rzz/atc/issues/182)
- Originally reported under [#754](https://github.com/zlsa/atc/issues/754)



Expand Down
3 changes: 2 additions & 1 deletion src/assets/scripts/airport/AirspaceModel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _isEqual from 'lodash/isEqual';
import _isNumber from 'lodash/isNumber';
import _map from 'lodash/map';
import BaseModel from '../base/BaseModel';
import PositionModel from '../base/PositionModel';
Expand Down Expand Up @@ -30,7 +31,7 @@ export default class AirspaceModel extends BaseModel {
constructor(airspace, airportPosition, magneticNorth) {
super();

if (!airspace || !airportPosition || !magneticNorth) {
if (!airspace || !airportPosition || !_isNumber(magneticNorth)) {
// eslint-disable-next-line max-len
throw new TypeError('Invalid parameter, expected airspace, airportPosition and magneticNorth to be defined');
}
Expand Down
3 changes: 2 additions & 1 deletion src/assets/scripts/base/PositionModel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _isNumber from 'lodash/isNumber';
import _uniqueId from 'lodash/uniqueId';
import {
calculateDistanceToPointForX,
Expand Down Expand Up @@ -245,7 +246,7 @@ export default class PositionModel {
* @static
*/
PositionModel.calculatePosition = (coordinates, referencePostion, magneticNorth) => {
if (!coordinates || !referencePostion || !magneticNorth) {
if (!coordinates || !referencePostion || !_isNumber(magneticNorth)) {
throw new TypeError('Invalid parameter. PositionModel.getPosition() requires coordinates, referencePostion ' +
'and magneticNorth as parameters');
}
Expand Down
4 changes: 4 additions & 0 deletions test/airport/AirspaceModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ ava('throws if called with invalid parameters', t => {
t.throws(() => new AirspaceModel(AIRSPACE_MOCK, airportPositionFixtureKSFO));
});

ava('does not throw when instantiated with a 0 magneticNorth', t => {
t.notThrows(() => new AirspaceModel(AIRSPACE_MOCK, airportPositionFixtureKSFO, 0));
})

ava('accepts an airspace object that is used to set the class properties', t => {
const model = new AirspaceModel(AIRSPACE_MOCK, airportPositionFixtureKSFO, magneticNorth);

Expand Down
6 changes: 6 additions & 0 deletions test/base/PositionModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ ava('.getPostiion() returns an array with a calculated x, y value that is the sa

t.true(_isEqual(result, expectedResult.position));
});

// user bug test cases
ava('.calculatePosition() does not throw when it receives 0 for magnetic_north', t => {
t.notThrows(() => new PositionModel(LAT_LONG_MOCK, airportPositionFixtureKLAS, 0));
t.notThrows(() => PositionModel.calculatePosition(LAT_LONG_MOCK, airportPositionFixtureKLAS, 0));
});

0 comments on commit 57aacc3

Please sign in to comment.