Comparing version 0.0.9-alpha.6 to 0.0.9-alpha.7
@@ -153,2 +153,27 @@ "use strict"; | ||
}); | ||
tap.test('/students/s2/class', function (t) { | ||
var request = api.parseRequest(['students', 's2', 'class']), query = api.buildQuery(request); | ||
t.equal(query.steps.length, 5, 'should build a 5 step query'); | ||
t.ok(query.steps[0] instanceof builder.ExtendContextQueryStep, 'EXTEND'); | ||
t.ok(query.steps[1] instanceof builder.QueryEdgeQueryStep, 'QUERY /students'); | ||
t.ok(query.steps[2] instanceof builder.ProvideIdQueryStep, 'PROVIDE ID: classId'); | ||
t.ok(query.steps[3] instanceof builder.ExtendContextQueryStep, 'APPLY PARAMS'); | ||
t.ok(query.steps[4] instanceof builder.QueryEdgeQueryStep, 'QUERY /classes'); | ||
query.execute() | ||
.then(function (resp) { | ||
t.same(resp.data, { | ||
id: "c1", | ||
name: "A", | ||
semester: 1, | ||
room: "Room 1", | ||
schoolId: "s1" | ||
}); | ||
t.equal(resp.metadata, null); | ||
t.end(); | ||
}) | ||
.catch(function () { | ||
t.ok(false, "a valid query should not fail"); | ||
t.end(); | ||
}); | ||
}); | ||
tap.test('/schools/s1/classes/c2', function (t) { | ||
@@ -192,2 +217,35 @@ var request = api.parseRequest(['schools', 's1', 'classes', 'c2']), query = api.buildQuery(request); | ||
}); | ||
tap.test('DELETE /schools/s3', function (t) { | ||
var request = api.parseRequest(['schools', 's3']); | ||
request.type = ApiRequest_1.ApiRequestType.Delete; | ||
var query = api.buildQuery(request); | ||
t.equal(query.steps.length, 3, 'should build a 3 step query'); | ||
t.ok(query.steps[0] instanceof builder.ExtendContextQueryStep); | ||
t.ok(query.steps[1] instanceof builder.ExtendContextQueryStep); | ||
t.ok(query.steps[2] instanceof builder.QueryEdgeQueryStep); | ||
query.execute() | ||
.then(function (resp) { | ||
t.equal(resp.metadata, null); | ||
t.end(); | ||
}) | ||
.catch(function () { | ||
t.ok(false, "a valid query should not fail"); | ||
t.end(); | ||
}); | ||
}); | ||
tap.test('DELETE /students/s2/class', function (t) { | ||
var request = api.parseRequest(['students', 's2', 'class']); | ||
request.type = ApiRequest_1.ApiRequestType.Delete; | ||
try { | ||
api.buildQuery(request); | ||
t.ok(false, "an invalid query should not succeed"); | ||
t.end(); | ||
} | ||
catch (e) { | ||
t.ok(e instanceof ApiEdgeError_1.ApiEdgeError); | ||
t.equal(e.status, 400); | ||
t.equal(e.message, 'Invalid Delete Query'); | ||
t.end(); | ||
} | ||
}); | ||
tap.test('PATCH /schools/s2', function (t) { | ||
@@ -194,0 +252,0 @@ var request = api.parseRequest(['schools', 's2']); |
{ | ||
"name": "api-core", | ||
"version": "0.0.9-alpha.6", | ||
"version": "0.0.9-alpha.7", | ||
"description": "Lightweight framework for building dynamic multi-level APIs for any provider (Express, socket.io, etc.), consumable via multiple channels (HTTP, socket.io, etc.)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -186,2 +186,31 @@ import {ApiEdgeError} from "../src/query/ApiEdgeError"; | ||
tap.test('/students/s2/class', (t: any) => { | ||
const request = api.parseRequest([ 'students', 's2', 'class' ]), | ||
query = api.buildQuery(request); | ||
t.equal(query.steps.length, 5, 'should build a 5 step query'); | ||
t.ok(query.steps[0] instanceof builder.ExtendContextQueryStep, 'EXTEND'); | ||
t.ok(query.steps[1] instanceof builder.QueryEdgeQueryStep, 'QUERY /students'); | ||
t.ok(query.steps[2] instanceof builder.ProvideIdQueryStep, 'PROVIDE ID: classId'); | ||
t.ok(query.steps[3] instanceof builder.ExtendContextQueryStep, 'APPLY PARAMS'); | ||
t.ok(query.steps[4] instanceof builder.QueryEdgeQueryStep, 'QUERY /classes'); | ||
query.execute() | ||
.then(resp => { | ||
t.same(resp.data, { | ||
id: "c1", | ||
name: "A", | ||
semester: 1, | ||
room: "Room 1", | ||
schoolId: "s1" | ||
}); | ||
t.equal(resp.metadata, null); | ||
t.end() | ||
}) | ||
.catch(() => { | ||
t.ok(false, "a valid query should not fail"); | ||
t.end() | ||
}); | ||
}); | ||
tap.test('/schools/s1/classes/c2', (t: any) => { | ||
@@ -231,2 +260,40 @@ const request = api.parseRequest([ 'schools', 's1', 'classes', 'c2' ]), | ||
tap.test('DELETE /schools/s3', (t: any) => { | ||
const request = api.parseRequest([ 'schools', 's3' ]); | ||
request.type = ApiRequestType.Delete; | ||
const query = api.buildQuery(request); | ||
t.equal(query.steps.length, 3, 'should build a 3 step query'); | ||
t.ok(query.steps[0] instanceof builder.ExtendContextQueryStep); | ||
t.ok(query.steps[1] instanceof builder.ExtendContextQueryStep); | ||
t.ok(query.steps[2] instanceof builder.QueryEdgeQueryStep); | ||
query.execute() | ||
.then(resp => { | ||
t.equal(resp.metadata, null); | ||
t.end() | ||
}) | ||
.catch(() => { | ||
t.ok(false, "a valid query should not fail"); | ||
t.end() | ||
}); | ||
}); | ||
tap.test('DELETE /students/s2/class', (t: any) => { | ||
const request = api.parseRequest([ 'students', 's2', 'class' ]); | ||
request.type = ApiRequestType.Delete; | ||
try { | ||
api.buildQuery(request); | ||
t.ok(false, "an invalid query should not succeed"); | ||
t.end() | ||
} | ||
catch(e) { | ||
t.ok(e instanceof ApiEdgeError); | ||
t.equal(e.status, 400); | ||
t.equal(e.message, 'Invalid Delete Query'); | ||
t.end() | ||
} | ||
}); | ||
tap.test('PATCH /schools/s2', (t: any) => { | ||
@@ -233,0 +300,0 @@ const request = api.parseRequest([ 'schools', 's2' ]); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
499365
170
6511