Skip to content

Commit

Permalink
added query spies on every step
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Jul 6, 2015
1 parent 4103db2 commit eba21d0
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 60 deletions.
6 changes: 6 additions & 0 deletions es5/spec/app.index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ describe("forbin-scudl", function () {
it("creates the controller", function () {
assert.file(["app/controllers/" + name + "Controller.js"]);
});

describe("(about the content of every feature)", function () {
it("should have some this.querySpy = on it", function () {
assert.fileContent([["features/steps/" + name + "/" + name + "Controller.show.steps.js", "this.querySpy ="]]);
});
});
});
6 changes: 6 additions & 0 deletions es6/spec/app.index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ describe("forbin-scudl", () => {
`app/controllers/${name}Controller.js`
]);
});

describe("(about the content of every feature)", () => {
it("should have some this.querySpy = on it", () => {
assert.fileContent([[`features/steps/${name}/${name}Controller.show.steps.js`, "this.querySpy ="]]);
});
});
});
18 changes: 1 addition & 17 deletions generators/app/templates/app/controllers/_modelController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ export default class <%= Name %>Controller extends ApplicationController {
} else {
let new<%= Name %> = new <%= Name %>({
contentPackageId: request.body.data.contentPackageId,
name: request.body.data.name,
type: request.body.data.type,
creatorName: request.body.data.creatorName,
collectionName: request.body.data.collectionName,
categoryName: request.body.data.categoryName,
mimeType: request.body.data.mimeType,
priceInCredits: request.body.data.priceInCredits,
description: request.body.data.description,
copyright: request.body.data.copyright
name: request.body.data.name
});

new<%= Name %>.save((saveError) => {
Expand Down Expand Up @@ -63,14 +55,6 @@ export default class <%= Name %>Controller extends ApplicationController {
} else {
<%= name %>.contentPackageId = request.body.data.contentPackageId;
<%= name %>.name = request.body.data.name;
<%= name %>.type = request.body.data.type;
<%= name %>.creatorName = request.body.data.creatorName;
<%= name %>.collectionName = request.body.data.collectionName;
<%= name %>.categoryName = request.body.data.categoryName;
<%= name %>.mimeType = request.body.data.mimeType;
<%= name %>.priceInCredits = request.body.data.priceInCredits;
<%= name %>.description = request.body.data.description;
<%= name %>.copyright = request.body.data.copyright;

<%= name %>.save((saveError) => {
if(saveError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Request from "appeal";
export default function <%= Name %>ControllerShowSteps () {
this.When(/^a valid create <%= name %> request is received$/, function (callback) {
this.database.mock({
//TODO ADD MOCKS WITH ATTRIBUTES
"select * from `client_access_tokens` where `token` = 'valid-client-access-token' and `deleted_at` is null limit 1": [
this.clientAccessTokenRecord
],
Expand All @@ -17,6 +16,10 @@ export default function <%= Name %>ControllerShowSteps () {
]
});

//TODO: ADD ATTRIBUTES
//new RegExp(`insert into `<%= names %>` \(`created_at`, `title`\) values \('[0-9\:\- \.]*', '${<%= name %>Fixtures[0].title}'\)`)
this.querySpy = this.database.spy(/insert into `<%= _name %>s` \(`created_at`, `title`\) values \('[0-9\:\- \.]*', ''\)/, [12]);

Request
.post
.url(this.url + "/<%= name %>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function <%= Name %>ControllerListSteps () {
]
});

this.deleteQuerySpy = this.database.spy(/update `<%= _name %>s` set `deleted_at` = '[0-9\:\- \.]*' where `id` = 1/, 1);
this.querySpy = this.database.spy(/update `<%= _name %>s` set `deleted_at` = '[0-9\:\- \.]*' where `id` = 1/, 1);

Request
.delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import Request from "appeal";
export default function <%= Name %>ControllerListSteps () {
this.When(/^a valid list <%= name %> request is received$/, function (callback) {
this.database.mock({
"select * from `<%= _name %>s`": [
<%= name %>Fixtures[0],
<%= name %>Fixtures[2],
<%= name %>Fixtures[3],
<%= name %>Fixtures[4],
<%= name %>Fixtures[5]
],
"select * from `client_access_tokens` where `token` = 'valid-client-access-token' and `deleted_at` is null limit 1": [
this.clientAccessTokenRecord
],
Expand All @@ -23,6 +16,14 @@ export default function <%= Name %>ControllerListSteps () {
]
});

this.querySpy = this.database.spy("select * from `<%= _name %>s`", [
<%= name %>Fixtures[0],
<%= name %>Fixtures[2],
<%= name %>Fixtures[3],
<%= name %>Fixtures[4],
<%= name %>Fixtures[5]
]);

Request
.get
.url(this.url + "/<%= name %>s")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export default function <%= Name %>ControllerShowSteps () {
"select * from `client_access_tokens` where `token` = 'expired-client-access-token' and `deleted_at` is null limit 1": [
this.clientAccessTokenRecord
],
"select * from `<%= _name %>s` where `id` = '1' and `deleted_at` is null limit 1": [
<%= name %>Fixtures[0]
],
"select * from `<%= _name %>s` where `id` = '2' and `deleted_at` is null limit 1": [
]
});

this.querySpy = this.database.spy("select * from `<%= _name %>s` where `id` = '1' and `deleted_at` is null limit 1", [
<%= name %>Fixtures[0]
]);

Request
.get
.url(this.url + "/<%= name %>/" + this.<%= name %>Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Request from "appeal";
export default function <%= Name %>ControllerUpdateSteps () {
this.When(/^a valid update <%= name %> request is received$/, function (callback) {
this.database.mock({
//TODO ADD MOCKS WITH ATTRIBUTES
"select * from `<%= _name %>s` where `id` = '2' and `deleted_at` is null limit 1": [
],
"select * from `<%= _name %>s` where `id` = '1' and `deleted_at` is null limit 1": [
Expand All @@ -30,6 +29,9 @@ export default function <%= Name %>ControllerUpdateSteps () {
this.<%= name %>.name = "newName";
}

//TODO ADD MOCKS WITH ATTRIBUTES
this.querySpy = this.database.spy(/update `<%= _name %>s` set `title` = 'newName', `updated_at` = '[0-9\:\- \.]*' where `id` = 1/, [1]);

Request
.put
.url(this.url + "/<%= name %>/" + this.<%= name %>Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Create a new <%= name %>
When a valid create <%= name %> request is received
Then respond with the newly created <%= name %>'s details
And http status code "created"
And the "insert" query was executed
Scenario: client access token is valid and authorized, but <%= name %> attributes are not valid
Given client access token is valid
Expand All @@ -20,7 +21,7 @@ Feature: Create a new <%= name %>
When a valid create <%= name %> request is received
Then respond with error message title, "<%= Name %> is invalid"
And http status code "conflict"
# Scenario: client access token is valid, but unauthorized
Scenario: client access token is invalid, return error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Delete an existing <%= Name %>
And <%= name %> is found
When a valid delete <%= name %> request is received
Then respond with http status code "no content"
And the delete query was executed
And the "delete" query was executed

Scenario: client access token is valid, authorized, but <%= name %> does not exist
Given client access token is valid
Expand All @@ -15,14 +15,14 @@ Feature: Delete an existing <%= Name %>
When a valid delete <%= name %> request is received
Then respond with error message, "There is no <%= Name %> for the given (id)."
And http status code "not found"

# Scenario: client access token is valid and unauthorized, return error

Scenario: client access token is invalid
Given client access token is invalid
When a valid delete <%= name %> request is received
Then respond with error message, "The client access token provided is invalid."
And http status code "unauthorized"
And http status code "unauthorized"

Scenario: client access token is valid but expired, return error
Given client access token is expired
Expand All @@ -33,4 +33,4 @@ Feature: Delete an existing <%= Name %>
Scenario: request malformed, return error
When an invalid delete <%= name %> request is received
Then respond with error message, "Malformed request."
And http status code "bad request"
And http status code "bad request"
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Feature: List all <%= name %> details
When a valid list <%= name %> request is received
Then respond with all the list of <%= name %>s
And http status code "ok"
And the "select all" query was executed

# Scenario: client access token is valid, but unauthorized

Scenario: client access token is invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@ Feature: Show an existing <%= name %>'s details
Scenario: client access token is valid, authorized, and <%= name %> identifier is valid
Given client access token is valid
#And client access token is authorized
And <%= name %> is found
#And client access token is authorized
And <%= name %> is found
When a valid show <%= name %> details request is received
Then respond with the specified <%= name %>'s details
And http status code "ok"
And http status code "ok"
And the "select" query was executed
Scenario: client access token is valid and authorized, but the <%= name %> is not found
Given client access token is valid
#And client access token is authorized
And <%= name %> is not found
#And client access token is authorized
And <%= name %> is not found
When a valid show <%= name %> details request is received
Then respond with error message, "There is no <%= Name %> for the given (id)."
And http status code "not found"
And http status code "not found"
# Scenario: client access token is valid, but unauthorized
Scenario: client access token is invalid
Given client access token is invalid
When a valid show <%= name %> details request is received
Then respond with error message, "The client access token provided is invalid."
And http status code "unauthorized"
And http status code "unauthorized"
Scenario: client access token is valid but expired, return error
Given client access token is expired
Expand All @@ -37,4 +38,4 @@ Feature: Show an existing <%= name %>'s details
Scenario: request malformed, return error
When an invalid show <%= name %> details request is received
Then respond with error message, "Malformed request."
And http status code "bad request"
And http status code "bad request"
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,38 @@ Feature: Update an existing <%= name %>
Scenario: client access token is valid and authorized, <%= name %> identifier is valid, and <%= name %> attributes are valid
Given client access token is valid
#And client access token is authorized
And <%= name %> parameters are valid
And <%= name %> is found
#And client access token is authorized
And <%= name %> parameters are valid
And <%= name %> is found
When a valid update <%= name %> request is received
Then respond with the updated <%= name %>'s details
And http status code "ok"
And http status code "ok"
And the "update" query was executed
Scenario: client access token is valid and authorized, but <%= name %> identifier is not valid
Given client access token is valid
And <%= name %> parameters are valid
And <%= name %> is not found
And <%= name %> parameters are valid
And <%= name %> is not found
When a valid update <%= name %> request is received
Then respond with error message, "There is no <%= Name %> for the given (id)."
And http status code "not found"
And http status code "not found"
Scenario: client access token is valid and authorized, <%= name %> identifier is valid, but <%= name %> attributes are not valid
Given client access token is valid
#And client access token is authorized
And <%= name %> is found
And <%= name %> parameters are invalid
#And client access token is authorized
And <%= name %> is found
And <%= name %> parameters are invalid
When a valid update <%= name %> request is received
Then respond with error message title, "<%= Name %> is invalid"
And http status code "conflict"
And http status code "conflict"
# Scenario: client access token is valid, but unauthorized
Scenario: client access token is invalid
Given client access token is invalid
When a valid update <%= name %> request is received
Then respond with error message, "The client access token provided is invalid."
And http status code "unauthorized"
And http status code "unauthorized"
Scenario: client access token is valid but expired, return error
Given client access token is expired
Expand All @@ -49,4 +50,4 @@ Feature: Update an existing <%= name %>
Scenario: request id malformed
When an invalid update <%= name %> request is received
Then respond with error message, "Malformed request."
And http status code "bad request"
And http status code "bad request"
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
},
"homepage": "https://github.com/FreeAllMedia/generator-forbin-scudl",
"dependencies": {
"babel-eslint": "^3.1.23",
"chalk": "^1.1.0",
"eslint": "^0.24.0",
"jargon": "^0.1.14",
"yeoman-generator": "^0.20.1",
"yo": "^1.4.7",
Expand Down

0 comments on commit eba21d0

Please sign in to comment.