Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
aluisiora committed Mar 6, 2018
2 parents 3e8e3ca + 958f901 commit eda0334
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "routeros-client",
"version": "0.8.0",
"version": "0.8.1",
"description": "Easy to use abstraction layer over the node-routeros API",
"main": "./dist/index",
"types": "./dist/index",
Expand Down
3 changes: 2 additions & 1 deletion src/RosApiCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,15 @@ export class RosApiCommands extends RouterOSAPICrud {
}

/**
* Returns the first item if found
* Returns the first item if found, else return null
*
* @param data optional filtering, like what you get when using the where function
*/
public find(data?: object): Promise<object> {
return this.get(data).then((results) => {
let result: object = new Object();
if (results.length > 0) result = results[0];
else result = null;
return Promise.resolve(result);
}).catch((err: RosException) => {
return Promise.reject(err);
Expand Down
2 changes: 1 addition & 1 deletion src/RosApiCrud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ export abstract class RouterOSAPICrud {
return Promise.all(promises).then((results) => {
for (let result of results) {
if (Array.isArray(result)) result = result.shift();
if (!result) return Promise.reject(new RosException("REFNOTFND"));
const consulted = consultedIndexes.shift();
if (!result) return Promise.reject(new RosException("REFNOTFND", { key: consulted.key}));
if (consulted.key === "place-after") {
this.placeAfter = result[".id"];
consulted.key = "place-before";
Expand Down
18 changes: 18 additions & 0 deletions test/2.printing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ describe("RosApiCommands", () => {

describe("printing and filtering prints", () => {

it("should get return nothing from /interface where name is ether6", (done) => {
api.menu("/interface").where("name", "ether6").getOnly().then((interf) => {
expect(interf).to.be.equal(null);
done();
}).catch((err) => {
done(err);
});
});

it("should get return nothing from /ip firewall raw", (done) => {
api.menu("/ip firewall raw").get().then((rules) => {
rules.length.should.be.equal(0);
done();
}).catch((err) => {
done(err);
});
});

it("should get all interfaces from /interface", (done) => {
api.menu("/interface").get().then((interfaces) => {
interfaces.length.should.be.above(0);
Expand Down

0 comments on commit eda0334

Please sign in to comment.