Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dirk Van Haerenborgh <dirk.vanhaerenborgh@aloxy.io>
  • Loading branch information
vhdirk committed Feb 4, 2021
1 parent c038eb6 commit b21fd70
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 11 deletions.
14 changes: 13 additions & 1 deletion javascript/lib/api/tests/client/http/features.http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('Http Features Handle', () => {
});
});

it('updates a Feature', () => {
it('creates a Feature', () => {
return H.test({
toTest: () => handle.putFeature(H.feature),
testBody: H.feature.toObject(),
Expand All @@ -101,6 +101,18 @@ describe('Http Features Handle', () => {
});
});

it('updates a Feature', () => {
return H.test({
toTest: () => handle.putFeature(H.feature),
testBody: H.feature.toObject(),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/${H.feature.id}`,
method: 'put',
status: 204,
payload: H.feature.toJson()
});
});

it('updates a Definition', () => {
return H.test({
toTest: () => handle.putDefinition(H.feature.id, H.definition),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class TestRequester implements HttpRequester {
}
this.requests.forEach((response, request) => {
if (this.matches(method, url, header, body, request)) {
this.requests.delete(request);
resolve(response);
}
});
Expand Down
96 changes: 90 additions & 6 deletions javascript/lib/api/tests/client/http/policies.http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Http Policies Handle', () => {
});
});

it('puts a Policy', () => {
it('creates a Policy', () => {
return H.test({
toTest: () => handle.putPolicy(policy),
testBody: policy.toObject(),
Expand All @@ -135,6 +135,30 @@ describe('Http Policies Handle', () => {
});
});

it('updates a Policy', () => {
return H.test({
toTest: () => handle.putPolicy(policy),
testBody: policy.toObject(),
expected: new PutResponse(null, 204, undefined),
request: baseRequest,
method: 'put',
status: 204,
payload: policy.toJson()
});
});

it('creates Entries', () => {
return H.test({
toTest: () => handle.putEntries(policy.id, entries),
testBody: Entries.toObject(entries),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/entries`,
method: 'put',
status: 204,
payload: Entries.toJson(entries)
});
});

it('updates Entries', () => {
return H.test({
toTest: () => handle.putEntries(policy.id, entries),
Expand All @@ -147,7 +171,7 @@ describe('Http Policies Handle', () => {
});
});

it('updates an Entry', () => {
it('creates an Entry', () => {
return H.test({
toTest: () => handle.putEntry(policy.id, anEntry),
testBody: anEntry.toObject(),
Expand All @@ -159,7 +183,19 @@ describe('Http Policies Handle', () => {
});
});

it('updates Subjects', () => {
it('updates an Entry', () => {
return H.test({
toTest: () => handle.putEntry(policy.id, anEntry),
testBody: anEntry.toObject(),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/entries/${label}`,
method: 'put',
status: 204,
payload: anEntry.toJson()
});
});

it('creates Subjects', () => {
return H.test({
toTest: () => handle.putSubjects(policy.id, label, subjects),
testBody: Subjects.toObject(subjects),
Expand All @@ -171,7 +207,19 @@ describe('Http Policies Handle', () => {
});
});

it('updates a Subject', () => {
it('updates Subjects', () => {
return H.test({
toTest: () => handle.putSubjects(policy.id, label, subjects),
testBody: Subjects.toObject(subjects),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/entries/${label}/subjects`,
method: 'put',
status: 204,
payload: Subjects.toJson(subjects)
});
});

it('creates a Subject', () => {
return H.test({
toTest: () => handle.putSubject(policy.id, label, aSubject),
testBody: aSubject.toObject(),
Expand All @@ -183,7 +231,19 @@ describe('Http Policies Handle', () => {
});
});

it('updates Resources', () => {
it('updates a Subject', () => {
return H.test({
toTest: () => handle.putSubject(policy.id, label, aSubject),
testBody: aSubject.toObject(),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/entries/${label}/subjects/${subjectId}`,
method: 'put',
status: 204,
payload: aSubject.toJson()
});
});

it('creates Resources', () => {
return H.test({
toTest: () => handle.putResources(policy.id, label, resources),
testBody: Resources.toObject(resources),
Expand All @@ -195,7 +255,19 @@ describe('Http Policies Handle', () => {
});
});

it('updates a Resource', () => {
it('updates Resources', () => {
return H.test({
toTest: () => handle.putResources(policy.id, label, resources),
testBody: Resources.toObject(resources),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/entries/${label}/resources`,
method: 'put',
status: 204,
payload: Resources.toJson(resources)
});
});

it('creates a Resource', () => {
return H.test({
toTest: () => handle.putResource(policy.id, label, aResource),
testBody: aResource.toObject(),
Expand All @@ -207,6 +279,18 @@ describe('Http Policies Handle', () => {
});
});

it('updates a Resource', () => {
return H.test({
toTest: () => handle.putResource(policy.id, label, aResource),
testBody: aResource.toObject(),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/entries/${label}/resources/${resourcePath}`,
method: 'put',
status: 204,
payload: aResource.toJson()
});
});

it('deletes a Policy', () => {
return H.test({
toTest: () => handle.deletePolicy(policy.id),
Expand Down
45 changes: 41 additions & 4 deletions javascript/lib/api/tests/client/http/things.http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Http Things Handle', () => {
});
});

it('puts a Thing', () => {
it('puts a new Thing', () => {
return H.test({
toTest: () => handleV2.putThing(H.thing),
testBody: H.thing.toObject(),
Expand All @@ -157,6 +157,18 @@ describe('Http Things Handle', () => {
});
});

it('puts a Thing that already exists', () => {
return H.test({
toTest: () => handleV2.putThing(H.thing),
testBody: H.thing.toObject(),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}`,
method: 'put',
status: 204,
payload: H.thing.toJson()
});
});

it('updates a policyId', () => {
return H.test({
toTest: () => handleV2.putPolicyId(H.thing.thingId, 'ID'),
Expand All @@ -169,7 +181,7 @@ describe('Http Things Handle', () => {
});
});

it('updates an Attribute', () => {
it('creates Attributes', () => {
return H.test({
toTest: () => handleV2.putAttributes(H.thing.thingId, H.attributes),
testBody: H.attributes,
Expand All @@ -181,7 +193,19 @@ describe('Http Things Handle', () => {
});
});

it('updates an Attribute', () => {
it('updates Attributes', () => {
return H.test({
toTest: () => handleV2.putAttributes(H.thing.thingId, H.attributes),
testBody: H.attributes,
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/attributes`,
method: 'put',
status: 204,
payload: JSON.stringify(H.attributes)
});
});

it('creates an Attribute', () => {
return H.test({
toTest: () => handleV2.putAttribute(H.thing.thingId, H.attributePath, H.attribute),
testBody: H.attribute,
Expand All @@ -204,7 +228,7 @@ describe('Http Things Handle', () => {
});
});

it('updates an AclEntry', () => {
it('creates an AclEntry', () => {
return H.test({
toTest: () => handleV1.putAclEntry(H.thing.thingId, anAclEntry),
testBody: anAclEntry.toObject(),
Expand All @@ -217,6 +241,19 @@ describe('Http Things Handle', () => {
});
});

it('updates an AclEntry', () => {
return H.test({
toTest: () => handleV1.putAclEntry(H.thing.thingId, anAclEntry),
testBody: anAclEntry.toObject(),
expected: new PutResponse(null, 204, undefined),
request: `${baseRequest}/acl/${authorizationSubject}`,
method: 'put',
status: 204,
payload: anAclEntry.toJson(),
api: 1
});
});

it('deletes a Thing', () => {
return H.test({
toTest: () => handleV2.deleteThing(H.thing.thingId),
Expand Down

0 comments on commit b21fd70

Please sign in to comment.