diff --git a/javascript/lib/api/src/client/handles/things.interfaces.ts b/javascript/lib/api/src/client/handles/things.interfaces.ts index ff57f867..79d3b067 100644 --- a/javascript/lib/api/src/client/handles/things.interfaces.ts +++ b/javascript/lib/api/src/client/handles/things.interfaces.ts @@ -64,7 +64,7 @@ export interface ThingsHandle { * @param options - Options to use for the request. * @returns A Promise for the response */ - putAttribute(thingId: string, attributePath: string, attributeValue: any, options?: MatchOptions): Promise; + putAttribute(thingId: string, attributePath: string, attributeValue: any, options?: MatchOptions): Promise>; /** * Deletes a Thing. @@ -163,7 +163,7 @@ export interface HttpThingsHandleV1 extends HttpThingsHandle { * @param options - Options to use for the request. * @returns A Promise for the response */ - putAcl(thingId: string, acl: Acl, options?: MatchOptions): Promise; + putAcl(thingId: string, acl: Acl, options?: MatchOptions): Promise>; /** * Updates an AclEntry of a Thing. diff --git a/javascript/lib/api/src/client/handles/things.ts b/javascript/lib/api/src/client/handles/things.ts index 71cfe3eb..da502589 100644 --- a/javascript/lib/api/src/client/handles/things.ts +++ b/javascript/lib/api/src/client/handles/things.ts @@ -174,9 +174,10 @@ export class DefaultThingsHandle implements WebSocketThingsHandle, HttpThingsHan } public putAttribute(thingId: string, attributePath: string, - attributeValue: any, options?: MatchOptions): Promise { - return this.requestFactory.fetchRequest({ + attributeValue: any, options?: MatchOptions): Promise> { + return this.requestFactory.fetchPutRequest({ verb: 'PUT', + parser: o => o, id: thingId, path: `attributes/${attributePath}`, requestOptions: options, @@ -195,9 +196,10 @@ export class DefaultThingsHandle implements WebSocketThingsHandle, HttpThingsHan }); } - public putAcl(thingId: string, acl: Acl, options?: MatchOptions): Promise { - return this.requestFactory.fetchRequest({ + public putAcl(thingId: string, acl: Acl, options?: MatchOptions): Promise> { + return this.requestFactory.fetchPutRequest({ verb: 'PUT', + parser: o => Acl.fromObject(o), id: thingId, path: 'acl', requestOptions: options, diff --git a/javascript/lib/api/src/model/response.ts b/javascript/lib/api/src/model/response.ts index 1a7e6c53..57e6d79e 100644 --- a/javascript/lib/api/src/model/response.ts +++ b/javascript/lib/api/src/model/response.ts @@ -33,7 +33,7 @@ export class PutResponse implements GenericResponse { } public wasCreated(): boolean { - return this.body !== undefined; + return this.body !== undefined && this.body !== null; } public wasUpdated(): boolean { diff --git a/javascript/lib/api/tests/client/http/features.http.spec.ts b/javascript/lib/api/tests/client/http/features.http.spec.ts index e1648526..3b05456e 100644 --- a/javascript/lib/api/tests/client/http/features.http.spec.ts +++ b/javascript/lib/api/tests/client/http/features.http.spec.ts @@ -77,7 +77,7 @@ describe('Http Features Handle', () => { }); }); - it('updates Features', () => { + it('creates Features', () => { return H.test({ toTest: () => handle.putFeatures(H.features), testBody: Features.toObject(H.features), @@ -89,6 +89,18 @@ describe('Http Features Handle', () => { }); }); + it('updates Features', () => { + return H.test({ + toTest: () => handle.putFeatures(H.features), + testBody: Features.toObject(H.features), + expected: new PutResponse(null, 204, undefined), + request: baseRequest, + method: 'put', + status: 204, + payload: Features.toJson(H.features) + }); + }); + it('creates a Feature', () => { return H.test({ toTest: () => handle.putFeature(H.feature), @@ -113,7 +125,7 @@ describe('Http Features Handle', () => { }); }); - it('updates a Definition', () => { + it('creates a Definition', () => { return H.test({ toTest: () => handle.putDefinition(H.feature.id, H.definition), testBody: H.definition, @@ -125,7 +137,19 @@ describe('Http Features Handle', () => { }); }); - it('updates Properties', () => { + it('updates a Definition', () => { + return H.test({ + toTest: () => handle.putDefinition(H.feature.id, H.definition), + testBody: H.definition, + expected: new PutResponse(null, 204, undefined), + request: `${baseRequest}/${H.feature.id}/definition`, + method: 'put', + status: 204, + payload: JSON.stringify(H.definition) + }); + }); + + it('creates Properties', () => { return H.test({ toTest: () => handle.putProperties(H.feature.id, H.properties), testBody: H.properties, @@ -137,7 +161,19 @@ describe('Http Features Handle', () => { }); }); - it('updates a Property', () => { + it('updates Properties', () => { + return H.test({ + toTest: () => handle.putProperties(H.feature.id, H.properties), + testBody: H.properties, + expected: new PutResponse(null, 204, undefined), + request: `${baseRequest}/${H.feature.id}/properties`, + method: 'put', + status: 204, + payload: JSON.stringify(H.properties) + }); + }); + + it('creates a Property', () => { return H.test({ toTest: () => handle.putProperty(H.feature.id, H.propertyPath, H.property), testBody: H.property, @@ -149,6 +185,18 @@ describe('Http Features Handle', () => { }); }); + it('updates a Property', () => { + return H.test({ + toTest: () => handle.putProperty(H.feature.id, H.propertyPath, H.property), + testBody: H.property, + expected: new PutResponse(null, 204, undefined), + request: `${baseRequest}/${H.feature.id}/properties/${H.propertyPath}`, + method: 'put', + status: 204, + payload: JSON.stringify(H.property) + }); + }); + it('deletes Features', () => { return H.test({ toTest: () => handle.deleteFeatures(), diff --git a/javascript/lib/api/tests/client/http/things.http.spec.ts b/javascript/lib/api/tests/client/http/things.http.spec.ts index e06f077d..2ba2567b 100644 --- a/javascript/lib/api/tests/client/http/things.http.spec.ts +++ b/javascript/lib/api/tests/client/http/things.http.spec.ts @@ -209,7 +209,7 @@ describe('Http Things Handle', () => { return H.test({ toTest: () => handleV2.putAttribute(H.thing.thingId, H.attributePath, H.attribute), testBody: H.attribute, - expected: { status: 201, headers: undefined, body: H.attribute }, + expected: new PutResponse(H.attribute, 201, undefined), request: `${baseRequest}/attributes/${H.attributePath}`, method: 'put', status: 201, @@ -217,10 +217,23 @@ describe('Http Things Handle', () => { }); }); + it('updates an Attribute', () => { + return H.test({ + toTest: () => handleV2.putAttribute(H.thing.thingId, H.attributePath, H.attribute), + testBody: H.attribute, + expected: new PutResponse(null, 204, undefined), + request: `${baseRequest}/attributes/${H.attributePath}`, + method: 'put', + status: 204, + payload: JSON.stringify(H.attribute) + }); + }); + it('updates an Acl', () => { return H.test({ toTest: () => handleV1.putAcl(H.thing.thingId, acl), request: `${baseRequest}/acl`, + expected: new PutResponse(null, 204, undefined), method: 'put', status: 204, payload: Acl.toJson(acl),