Skip to content

Commit

Permalink
feat(getByUnloc) add search by unloc functions, add unit test and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
marchah committed Apr 12, 2016
1 parent 68ca831 commit 71bc15b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ Return a JSON object with all the port with the unloc as key
}
```

## Methods

### getByUnloc(unloc)

Return the matched port, else undefined (alias: getByUNLOC, findByUnloc, findByUNLOC)

## Examples

````javascript
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

const ports = require('./lib/ports.json');

function getByUnloc(unloc) {
return ports[unloc];
}

module.exports = {
JSON: ports,
getByUnloc: getByUnloc,
getByUNLOC: getByUnloc,
findByUnloc: getByUnloc,
findByUNLOC: getByUnloc,
};
50 changes: 50 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const rewire = require('rewire');

const cbpPorts = rewire('../index.js');

const USLAX = cbpPorts.JSON.USLAX;

describe('Unit Testing ->', () => {
describe('JSON ->', () => {
it('should return an object', () => {
Expand All @@ -19,4 +21,52 @@ describe('Unit Testing ->', () => {
});
});
});
describe('Methods ->', () => {
describe('UNLOC #', () => {
describe('getByUnloc()', () => {
it('should be a function', () => {
expect(cbpPorts.getByUnloc).to.be.a('function');
});
it('should return object when find it', () => {
expect(cbpPorts.getByUnloc('USLAX')).that.is.an('object').to.eql(USLAX);
});
it('should return undefined when can\'t find it', () => {
expect(cbpPorts.getByUnloc('YUYUYU')).to.eql(undefined);
});
});
describe('getByUNLOC()', () => {
it('should be a function', () => {
expect(cbpPorts.getByUNLOC).to.be.a('function');
});
it('should return object when find it', () => {
expect(cbpPorts.getByUNLOC('USLAX')).that.is.an('object').to.eql(USLAX);
});
it('should return undefined when can\'t find it', () => {
expect(cbpPorts.getByUNLOC('YUYUYU')).to.eql(undefined);
});
});
describe('findByUnloc()', () => {
it('should be a function', () => {
expect(cbpPorts.findByUnloc).to.be.a('function');
});
it('should return object when find it', () => {
expect(cbpPorts.findByUnloc('USLAX')).that.is.an('object').to.eql(USLAX);
});
it('should return undefined when can\'t find it', () => {
expect(cbpPorts.findByUnloc('YUYUYU')).to.eql(undefined);
});
});
describe('findByUNLOC()', () => {
it('should be a function', () => {
expect(cbpPorts.findByUNLOC).to.be.a('function');
});
it('should return object when find it', () => {
expect(cbpPorts.findByUNLOC('USLAX')).that.is.an('object').to.eql(USLAX);
});
it('should return undefined when can\'t find it', () => {
expect(cbpPorts.findByUNLOC('YUYUYU')).to.eql(undefined);
});
});
});
});
});

0 comments on commit 71bc15b

Please sign in to comment.