Permalink
Browse files

fix(v2): fix handling of 204 codes

  • Loading branch information...
j-white committed Jul 4, 2017
1 parent f701187 commit a352ea8a096abf83562555c3eb14cb2565be4090
Showing with 21 additions and 1 deletion.
  1. +6 −0 src/api/OnmsResult.ts
  2. +5 −1 src/rest/AbstractHTTP.ts
  3. +7 −0 test/dao/AlarmDAO.spec.ts
  4. +3 −0 test/rest/MockHTTP21.ts
View
@@ -15,6 +15,12 @@ export class OnmsResult<T> {
return new OnmsResult(response, message || 'OK', code || 200, type);
}
/** create a new "No Content" result */
public static noContent() {
// Use an empty string for the data
return new OnmsResult('', 'No Content', 204);
}
/** the data, if any */
public data: T;
View
@@ -57,7 +57,11 @@ export abstract class AbstractHTTP implements IOnmsHTTP {
/** a convenience method for implementers to use to turn JSON into a javascript object */
protected transformJSON(data: any) {
if (typeof data === 'string') {
return JSON.parse(data);
if (data.length < 1) {
return {};
} else {
return JSON.parse(data);
}
} else {
// assume it's already parsed
return data;
@@ -77,4 +77,11 @@ describe('AlarmDAO with v2 API', () => {
expect(alarms[0].id).toEqual(6806);
});
});
it('AlarmDAO.find(uei=should-not-exist)', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('alarm.uei', Comparators.EQ, 'should-not-exist'));
return dao.find(filter).then((alarms) => {
expect(alarms.length).toEqual(0);
});
});
});
View
@@ -35,6 +35,9 @@ export class MockHTTP21 extends AbstractHTTP {
result.type = 'application/json';
return Promise.resolve(result);
}
case 'api/v2/alarms?limit=1000&_s=alarm.uei%3D%3Dshould-not-exist': {
return Promise.resolve(OnmsResult.noContent());
}
}
return Promise.reject(OnmsResult.error('Not yet implemented: ' + urlObj.toString()));
}

0 comments on commit a352ea8

Please sign in to comment.