Skip to content

Commit

Permalink
small fixes to input data validation, and README section added
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Feb 22, 2016
1 parent 2013a50 commit d7c611b
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 40 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ES6 yeoman generator for FAM troupe.

```
npm install -g generator-troupe
yo forbin-scudl
```

# Quality and Compatibility
Expand All @@ -26,8 +25,28 @@ cd node_modules/generator-troupe
gulp test-local
```

# Getting Started
You can generate troupe controllers with cucumber features with this generator.
# How to generate a SCUDL for a provider like AWS through Conan
All of the generators will ask you for the model name, which is singular and camelCased. Eg: apple, account, accountType

## 1. Generate the model
```
yo troupe:model
```
The models are generated with a default name property with a non empty validation. After the generation, is strongly recommended to add all the properties you need to validate, and all the relationships with other models.

## 2. Generate the functions
```
yo troupe:functions
```
This generator will create all the lambda classes to handle the SCUDL operations, all the necessary steps to do that, and it will create also a specialized class that returns all the meta data that a deployer like Conan may need. Every file will have their spec file to test it's functionality.

After this generation you will need to customize all the special steps, adding or removing everything that you may need, as well as the function metadata if necessary, like a timeout or anything.

## 3. Generate the resources
```
yo troupe:resources
```
In this case, the generated class will provide the deployer all the metadata that he may need in order to create the api/http resources that calls the lambda functions. Remember to add here any meta information for the specific resource that you may need.

# How to Contribute

Expand All @@ -39,7 +58,7 @@ We always aim to be friendly and helpful.

## Running Tests

It's easy to run the test suite locally, and *highly recommended* if you're using Generator-troupe.js on a platform we aren't automatically testing for.
It's easy to run the test suite locally, and *highly recommended* if you're using Troupe Generator on a platform we aren't automatically testing for.

```
npm test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import authorize from "../../steps/authorize.js";
import save<%= modelNamePluralPascal %> from "../../steps/<%= modelNamePlural %>/save<%= modelNamePluralPascal %>.js";
import <%= modelNamePascal %> from "../../models/<%= modelName %>.js";
import { local } from "../../../../environment.json";
import { getBadRequestError } from "../../errors.js";

Model.database = new Database(local);

Expand All @@ -16,14 +17,17 @@ export default class <%= modelNamePluralPascal %>Create {
this.database = Model.database;
this.actionContext = new ActionContext(input, context);
this.actionContext.permission = "<%= modelNamePlural %>:create";
this.actionContext.<%= modelName %>Parameters = jsonApiModelFormatter(input.data.data, <%= modelNamePascal %>);
delete this.actionContext.<%= modelName %>Parameters.id;
this.action = new Action(this.actionContext);
this.action.series(
authenticate,
authorize,
save<%= modelNamePluralPascal %>
);

if(input.data.data) {
this.actionContext.<%= modelName %>Parameters = jsonApiModelFormatter(input.data.data, <%= modelNamePascal %>);
delete this.actionContext.<%= modelName %>Parameters.id;
this.action = new Action(this.actionContext);
this.action.series(
authenticate,
authorize,
save<%= modelNamePluralPascal %>
);
}
}

/**
Expand All @@ -35,14 +39,18 @@ export default class <%= modelNamePluralPascal %>Create {
* @return {undefined} Returns nothing
*/
handler(input, context) {
this.action
.results((errors) => {
if (errors) {
context.done(errors);
} else {
const data = jsonApiModelFormatter(this.actionContext.<%= modelName %>);
context.done(null, { data });
}
});
if(this.action) {
this.action
.results((errors) => {
if (errors) {
context.done(errors);
} else {
const data = jsonApiModelFormatter(this.actionContext.<%= modelName %>);
context.done(null, { data });
}
});
} else {
context.done(getBadRequestError());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import fetch<%= modelNamePluralPascal %> from "../../steps/<%= modelNamePlural %
import save<%= modelNamePluralPascal %> from "../../steps/<%= modelNamePlural %>/save<%= modelNamePluralPascal %>.js";
import <%= modelNamePascal %> from "../../models/<%= modelName %>.js";
import { local } from "../../../../environment.json";
import { getBadRequestError } from "../../errors.js";

Model.database = new Database(local);

Expand All @@ -18,14 +19,17 @@ export default class <%= modelNamePluralPascal %>Update {
this.actionContext = new ActionContext(input, context);
this.actionContext.permission = "<%= modelNamePlural %>:update";
this.actionContext.<%= modelName %>Id = input.params.path.id;
this.actionContext.<%= modelName %>Parameters = jsonApiModelFormatter(input.data.data, <%= modelNamePascal %>);
this.action = new Action(this.actionContext);
this.action.series(
authenticate,
authorize,
fetch<%= modelNamePluralPascal %>,
save<%= modelNamePluralPascal %>
);

if(input.data.data) {
this.actionContext.<%= modelName %>Parameters = jsonApiModelFormatter(input.data.data, <%= modelNamePascal %>);
this.action = new Action(this.actionContext);
this.action.series(
authenticate,
authorize,
fetch<%= modelNamePluralPascal %>,
save<%= modelNamePluralPascal %>
);
}
}

/**
Expand All @@ -37,13 +41,17 @@ export default class <%= modelNamePluralPascal %>Update {
* @return {undefined} Returns nothing
*/
handler(input, context) {
this.action
.results((errors) => {
if (errors) {
context.done(errors);
} else {
context.done(null, { data: jsonApiModelFormatter(this.actionContext.<%= modelName %>) });
}
});
if(this.action) {
this.action
.results((errors) => {
if (errors) {
context.done(errors);
} else {
context.done(null, { data: jsonApiModelFormatter(this.actionContext.<%= modelName %>) });
}
});
} else {
context.done(getBadRequestError());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe("lambdas/<%= modelName %>Create.js", () => {
handlerClass.database.should.eql(Model.database);
});

it("should return an error if the input is not ok", done => {
callback = (handlerError) => {
handlerError.message.should.contain("BADREQUEST");
done();
};
delete input.data.data;
const apple = new ApplesCreate(input, context);
apple.handler(input, context);
});

describe("(permission)", () => {
it("should set the permission needed", () => {
handlerClass.actionContext.permission.should.equal("<%= modelNamePlural %>:create");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import jsonApiModelFormatter from "jsonapi-model-formatter";
chai.should();

import <%= modelNamePascal %> from "../../../dist/lib/models/<%= modelName %>.js";
import AccessToken from "../../../dist/lib/models/accessToken.js";
import <%= modelNamePluralPascal %>Update from "../../../dist/lib/lambdas/<%= modelNamePlural %>/<%= modelNamePlural %>Update.js";
import authenticate from "../../../dist/lib/steps/authenticate.js";
import authorize from "../../../dist/lib/steps/authorize.js";
Expand All @@ -17,6 +16,7 @@ describe("lambdas/<%= modelName %>Update.js", () => {
let input;
let handlerClass;
let callback;
let context;
let validAccessTokenParam;
let salt;

Expand Down Expand Up @@ -50,6 +50,16 @@ describe("lambdas/<%= modelName %>Update.js", () => {
handlerClass.database.should.eql(Model.database);
});

it("should return an error if the input is not ok", done => {
callback = (handlerError) => {
handlerError.message.should.contain("BADREQUEST");
done();
};
delete input.data.data;
const apple = new ApplesUpdate(input, context);
apple.handler(input, context);
});

describe("(permission)", () => {
it("should set the permission needed", () => {
handlerClass.actionContext.permission.should.equal("<%= modelNamePlural %>:update");
Expand Down
1 change: 0 additions & 1 deletion index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "generator-troupe",
"version": "0.1.2",
"description": "Generator for FAM troupe.",
"main": "index.js",
"main": "./es5/lib/app.index.js",
"scripts": {
"test": "gulp test"
},
Expand Down

0 comments on commit d7c611b

Please sign in to comment.