Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update garage.js resolve unit test error #4

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
launchConfigurations/
.git/
22 changes: 22 additions & 0 deletions api/controllers/garages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*jslint node: true */
'use strict';

var garageModel = require ('../models/garage');

module.exports = {
garages: garages,
};

/* return a list of garages (garage objects) */
function garages(req, res) {
// variables defined in the Swagger document can be referenced using req.swagger.params.{parameter_name}
if (req.swagger.params && req.swagger.params.garageId) {
var garageId = req.swagger.params.garageId.value;
var garageData = garageModel.getGarageById(garageId);

res.json(garageData);
} else {
var garages = garageModel.getAllGarages();
res.json(garages);
}
}
3 changes: 2 additions & 1 deletion api/controllers/hello_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module.exports = {
function hello(req, res) {
// variables defined in the Swagger document can be referenced using req.swagger.params.{parameter_name}
var name = req.swagger.params.name.value || 'stranger';
var helloname = util.format('Hello, %s!', name);
// 'Hello there' was 'Hello'
var helloname = util.format('Hello there, %s!', name);

// this sends back a JSON response which is a single string
res.json(helloname);
Expand Down
50 changes: 50 additions & 0 deletions api/models/garage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*jslint node: true */
'use strict';

module.exports = {
getGarageById: getGarageById,
getAllGarages: getAllGarages,
};

/* return a single Garage object */
function getGarageById(garageId) {
var foundApp = {};
for (var i = 0; i < GARAGES.length; i++) {
if (GARAGES[i].id == garageId) {
foundApp = GARAGES[i];
}
}

return foundApp;
}

function getAllGarages() {
return GARAGES;
}

// sample data
var GARAGES = [{
id: 6212,
name: 'Main door home',
lastUpdated: '2016-07-10T14:48:00',
desiredState: 'open',
status: 'open',
}, {
id: 6213,
name: 'Main door home',
lastUpdated: '2016-07-10T17:48:00',
desiredState: 'closed',
status: 'open',
}, {
id: 6214,
name: 'Main door home',
lastUpdated: '2016-07-10T17:48:00',
desiredState: 'closed',
status: 'closed',
}, {
id: 6215,
name: 'Main door home',
lastUpdated: '2016-07-10T17:48:00',
desiredState: 'open',
status: 'closed',
}];
57 changes: 57 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,51 @@ paths:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/garages:
# binds app logic to a route (api/controllers/applications.js)
x-swagger-router-controller: garages
get:
description: Returns a list of garages to the caller
# used as the method name of the controller inside garages.js
operationId: garages
responses:
"200":
description: Success
schema:
type: array
items:
# a pointer to a definition
$ref: "#/definitions/Garage"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/garages/{garageId}:
# Use the house address as the garageId
# binds app logic to a route (api/controllers/garages.js)
x-swagger-router-controller: garages
get:
description: Returns a single garage configuration to the caller
# used as the method name of the controller inside garages.js
operationId: garages
parameters:
- name: garageId
in: path
description: returns a garage object for the given id
# the path params are explicitly required by the spec
required: true
type: string
responses:
"200":
description: Successß
schema:
$ref: "#/definitions/Garage"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/hello:
# binds app logic to a route (api/controllers/hello_world.js)
x-swagger-router-controller: hello_world
Expand Down Expand Up @@ -100,6 +145,18 @@ definitions:
type: string
status:
type: string
Garage:
properties:
garageId:
type: string
name:
type: string
description:
type: string
desiredState:
type: string
status:
type: string
ErrorResponse:
required:
- message
Expand Down
2 changes: 1 addition & 1 deletion config/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Place configuration files in this directory.
Place configuration my files in this directory.
1 change: 1 addition & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
applications:
- disk_quota: 1024M
buildpack: nodejs_buildpack
host: devops-tutorial
name: devops-tutorial
command: node app.js
Expand Down
4 changes: 2 additions & 2 deletions test/api/controllers/hello_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('controllers', function() {
.end(function(err, res) {
should.not.exist(err);

res.body.should.eql('Hello, stranger!');
res.body.should.eql('Hello there, stranger!');

done();
});
Expand All @@ -39,7 +39,7 @@ describe('controllers', function() {
.end(function(err, res) {
should.not.exist(err);

res.body.should.eql('Hello, Scott!');
res.body.should.eql('Hello there, Scott!');

done();
});
Expand Down
2 changes: 2 additions & 0 deletions views/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<p><a href="/hello?name=joe">/hello?name=joe</a> <span class="description"><strong>GET</strong> request to /hello with a query string parameter of 'name=joe'</span></p>
<p><a href="/applications">/applications</a> <span class="description"><strong>GET</strong> request to /applications to get all the applications</span></p>
<p><a href="/applications/1234">/applications/1234</a> <span class="description"><strong>GET</strong> request to /applications/ with a path parameter of '1234' to get a specific application</span></p>
<p><a href="/garages">/garages</a> <span class="description"><strong>GET</strong> request to /garages to get all the garages</span></p>
<p><a href="/garages/6212">/garages/6212</a> <span class="description"><strong>GET</strong> request to /garages/ with a path parameter of '6212' to get a specific garage configuration</span></p>
<br />
<br />
<p><a href="/docs">Browse the Swagger UI</a></p>
Expand Down