This repository has been archived by the owner on Jan 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:data-studio/user-svc into dev
- Loading branch information
Showing
12 changed files
with
427 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
describe("APP_SCHEMA REST Schema", function () { | ||
|
||
let schema; | ||
|
||
let userId; | ||
let authorization; | ||
|
||
let login; | ||
let password; | ||
|
||
let $testClient; | ||
|
||
beforeEach(function (done) { | ||
|
||
schema = jasmine.startTestApi(); | ||
$testClient = jasmine.createTestClient(); | ||
|
||
login = $testClient.uniqueLogin(); | ||
password = $testClient.generatePassword(); | ||
|
||
$testClient.initUser(login, password, function (err, d) { | ||
if (err) return done(err); | ||
userId = d.UserId; | ||
authorization = d.TokenKey; | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
afterEach(function (done) { | ||
schema.server.close(done); | ||
}); | ||
|
||
describe("/app/:appId/schemas", function () { | ||
|
||
let appData; | ||
let app; | ||
let appId; | ||
|
||
let schemaData; | ||
|
||
beforeEach(function (done) { | ||
schemaData = { | ||
Name: "My Test Schema", | ||
}; | ||
appData = { | ||
Name: "My Test App", | ||
}; | ||
$testClient.$post(authorization, `/apps`, appData, function (err, res) { | ||
$testClient.$get(authorization, res.headers.location, function (err, res) { | ||
app = res.d; | ||
appId = app.Id; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("createAppSchema <POST> with valid parameters", function () { | ||
|
||
it("RETURNS `HTTP/1.1 403 Forbidden` WHEN `Authorization` HEADER IS NOT PROVIDED", function (done) { | ||
$testClient.$post(null, `/app/${appId}/schemas`, schemaData, function (err, res) { | ||
expect(res.statusCode).toBe(403); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("RETURNS `HTTP/1.1 303 See Other` WHEN `Authorization` HEADER IS PROVIDED", function (done) { | ||
$testClient.$post(authorization, `/app/${appId}/schemas`, schemaData, function (err, res) { | ||
expect(res.statusCode).toBe(303); | ||
expect(res.headers.location).toMatch(jasmine.idUrlRegexp("app", "schema")); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("CREATES AN APP SCHEMA", function (done) { | ||
$testClient.$post(authorization, `/app/${appId}/schemas`, schemaData, function (err, res) { | ||
$testClient.$get(authorization, res.headers.location, function (err, res) { | ||
expect(res.statusCode).toBe(200); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it("ADDS THE SCHEMA TO THE APPS LIST OF SCHEMAS", function (done) { | ||
$testClient.$post(authorization, `/app/${appId}/schemas`, schemaData, function (err, res) { | ||
let schemaId = res.headers.location.split(/\//g).pop(); | ||
$testClient.$get(authorization, `/app/${appId}`, function (err, res) { | ||
expect(res.statusCode).toBe(200); | ||
expect(res.d).toEqual(jasmine.objectContaining({ | ||
"Schemas": jasmine.arrayContaining([ | ||
jasmine.objectContaining({ | ||
"Id": schemaId | ||
}), | ||
]), | ||
})); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
|
||
describe("SCHEMA_PROPERTY REST API", function () { | ||
|
||
let api; | ||
|
||
let userId; | ||
let authorization; | ||
|
||
let login; | ||
let password; | ||
|
||
let $testClient; | ||
|
||
beforeEach(function (done) { | ||
|
||
api = jasmine.startTestApi(); | ||
$testClient = jasmine.createTestClient(); | ||
|
||
login = $testClient.uniqueLogin(); | ||
password = $testClient.generatePassword(); | ||
|
||
$testClient.initUser(login, password, function (err, d) { | ||
if (err) return done(err); | ||
userId = d.UserId; | ||
authorization = d.TokenKey; | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
afterEach(function (done) { | ||
api.server.close(done); | ||
}); | ||
|
||
describe("/schema/:schemaId/properties", function () { | ||
|
||
let app; | ||
let schema; | ||
let appData; | ||
let schemaData; | ||
let appId; | ||
let schemaId; | ||
|
||
let propertyData; | ||
|
||
beforeEach(function (done) { | ||
appData = { | ||
Name: "My Test App", | ||
}; | ||
schemaData = { | ||
Name: "My Test API", | ||
}; | ||
propertyData = { | ||
Key: "MyProp", | ||
}; | ||
$testClient.$post(authorization, `/apps`, appData, function (err, res) { | ||
$testClient.$get(authorization, res.headers.location, function (err, res) { | ||
app = res.d; | ||
appId = app.Id; | ||
$testClient.$post(authorization, `/app/${appId}/schemas`, schemaData, function (err, res) { | ||
$testClient.$get(authorization, res.headers.location, function (err, res) { | ||
schema = res.d; | ||
schemaId = schema.Id; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("createSchemaProperty <POST> with valid parameters", function () { | ||
|
||
it("RETURNS `HTTP/1.1 403 Forbidden` WHEN `Authorization` HEADER IS NOT PROVIDED", function (done) { | ||
$testClient.$post(null, `/schema/${schemaId}/properties`, propertyData, function (err, res) { | ||
expect(res.statusCode).toBe(403); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("RETURNS `HTTP/1.1 303 See Other` WHEN `Authorization` HEADER IS PROVIDED", function (done) { | ||
$testClient.$post(authorization, `/schema/${schemaId}/properties`, propertyData, function (err, res) { | ||
expect(res.statusCode).toBe(303); | ||
expect(res.headers.location).toMatch(jasmine.idUrlRegexp("schema", "property")); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("CREATES AN API PROPERTY", function (done) { | ||
$testClient.$post(authorization, `/schema/${schemaId}/properties`, propertyData, function (err, res) { | ||
$testClient.$get(authorization, res.headers.location, function (err, res) { | ||
expect(res.statusCode).toBe(200); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it("ADDS THE PROPERTY TO THE SCHEMAS LIST OF PROPERTIES", function (done) { | ||
$testClient.$post(authorization, `/schema/${schemaId}/properties`, propertyData, function (err, res) { | ||
let propId = res.headers.location.split(/\//g).pop(); | ||
$testClient.$get(authorization, `/schema/${schemaId}/properties`, function (err, res) { | ||
expect(res.statusCode).toBe(200); | ||
expect(res.d).toEqual(jasmine.arrayContaining([ | ||
jasmine.objectContaining({ | ||
"Id": propId | ||
}), | ||
])); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
|
||
module.exports = function Property (db) { | ||
|
||
const bookshelf = db._bookshelf; | ||
|
||
let Property = bookshelf.Model.extend({ | ||
tableName: 'schema_properties', | ||
constructor: function() { | ||
bookshelf.Model.apply(this, arguments); | ||
this.on('saving', function(model, attrs, options) { | ||
options.query.where('Id', '=', model.get("Id")); | ||
}); | ||
}, | ||
Schema: function() { | ||
return this.belongsTo(db.Schema, "SchemaId", "Id"); | ||
}, | ||
}); | ||
|
||
db.Property = Property; | ||
|
||
function fetchPropertyById (id) { | ||
return new Promise((resolve, reject) => { | ||
Property.where({"Id": id}) | ||
.fetch({withRelated: ["Schema"]}) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}; | ||
|
||
db.fetchPropertyById = fetchPropertyById; | ||
|
||
function fetchPropertiesBySchemaId (schemaId) { | ||
return new Promise((resolve, reject) => { | ||
Property.where({"SchemaId": schemaId, "Deleted": null}) | ||
.fetchAll() | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
} | ||
|
||
db.fetchPropertiesBySchemaId = fetchPropertiesBySchemaId; | ||
|
||
function fetchPropertyById (id) { | ||
return new Promise((resolve, reject) => { | ||
Property.where({"Id": id, "Deleted": null}) | ||
.fetch() | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
} | ||
|
||
db.fetchPropertyById = fetchPropertyById; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.