Skip to content

Commit

Permalink
refresh scudl with json api format for inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Feb 20, 2016
1 parent 6295574 commit 2013a50
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ActionContext from "../../actionContext.js";
import authenticate from "../../steps/authenticate.js";
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";

Model.database = new Database(local);
Expand All @@ -15,7 +16,8 @@ export default class <%= modelNamePluralPascal %>Create {
this.database = Model.database;
this.actionContext = new ActionContext(input, context);
this.actionContext.permission = "<%= modelNamePlural %>:create";
this.actionContext.<%= modelName %>Parameters = input.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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import authenticate from "../../steps/authenticate.js";
import authorize from "../../steps/authorize.js";
import fetch<%= modelNamePluralPascal %> from "../../steps/<%= modelNamePlural %>/fetch<%= modelNamePluralPascal %>.js";
import save<%= modelNamePluralPascal %> from "../../steps/<%= modelNamePlural %>/save<%= modelNamePluralPascal %>.js";
import <%= modelNamePascal %> from "../../models/<%= modelName %>.js";
import { local } from "../../../../environment.json";

Model.database = new Database(local);
Expand All @@ -17,7 +18,7 @@ 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 = input.data;
this.actionContext.<%= modelName %>Parameters = jsonApiModelFormatter(input.data.data, <%= modelNamePascal %>);
this.action = new Action(this.actionContext);
this.action.series(
authenticate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import <%= modelNamePascal %> from "../../models/<%= modelName %>.js";

export default function save<%= modelNamePluralPascal %>(actionContext, next) {
let <%= modelName %>Parameters;
if(actionContext.<%= modelName %>Parameters) {
<%= modelName %>Parameters = actionContext.<%= modelName %>Parameters;
if(actionContext.<%= modelName %>Parameters && actionContext.<%= modelName %>Parameters.attributes) {
<%= modelName %>Parameters = actionContext.<%= modelName %>Parameters.attributes;
}
actionContext.<%= modelName %> = new <%= modelNamePascal %>(<%= modelName %>Parameters);
if(actionContext.<%= modelName %>Id) {
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 %>Create from "../../../dist/lib/lambdas/<%= modelNamePlural %>/<%= modelNamePlural %>Create.js";
import authenticate from "../../../dist/lib/steps/authenticate.js";
import authorize from "../../../dist/lib/steps/authorize.js";
Expand Down Expand Up @@ -37,7 +36,7 @@ describe("lambdas/<%= modelName %>Create.js", () => {

input = {
params: validAccessTokenParam,
"data": { "name": "test <%= modelName %>" }
"data": { "data": { "type": "<%= modelNamePlural %>", "attributes": { "name": "test <%= modelName %>" } } }
};

handlerClass = new <%= modelNamePluralPascal %>Create(input, context);
Expand Down Expand Up @@ -69,7 +68,7 @@ describe("lambdas/<%= modelName %>Create.js", () => {

describe("(parameters)", () => {
it("should set the parameters for the save <%= modelName %> to use", () => {
handlerClass.actionContext.<%= modelName %>Parameters.should.eql({ "name": "test <%= modelName %>" });
handlerClass.actionContext.<%= modelName %>Parameters.should.eql(new <%= modelNamePascal %>({ "name": "test <%= modelName %>" }));
});

it("should not set an <%= modelName %> id", () => {
Expand Down Expand Up @@ -101,7 +100,6 @@ describe("lambdas/<%= modelName %>Create.js", () => {

describe("(when the steps are executed correctly)", () => {
let result;
let accessToken;
let expectedResponse;

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("lambdas/<%= modelName %>Update.js", () => {
};

input = {
"data": { "name": "test <%= modelName %>" },
"data": { "data": { "type": "<%= modelNamePlural %>", "attributes": { "name": "test <%= modelName %>" } } },
"params": validAccessTokenParam
};

Expand Down Expand Up @@ -76,7 +76,7 @@ describe("lambdas/<%= modelName %>Update.js", () => {

describe("(parameters)", () => {
it("should set the parameters for the save <%= modelName %> to use", () => {
handlerClass.actionContext.<%= modelName %>Parameters.should.eql({ "name": "test <%= modelName %>" });
handlerClass.actionContext.<%= modelName %>Parameters.should.eql(new <%= modelNamePascal %>({ "name": "test <%= modelName %>" }));
});

it("should set an <%= modelName %> id", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import save<%= modelNamePluralPascal %> from "../../../dist/lib/steps/<%= modelNamePlural %>/save<%= modelNamePluralPascal %>.js";
import <%= modelNamePascal %> from "../../../dist/lib/models/<%= modelName %>.js";
import regexs from "../../regexs.js";
import Model from "dovima";
import Database from "almaden";
Expand All @@ -19,7 +20,7 @@ describe("steps/save<%= modelNamePluralPascal %>.js", () => {
"debug": true
});

actionContext = { <%= modelName %>Parameters: { name: "guest" } };
actionContext = { <%= modelName %>Parameters: new <%= modelNamePascal %>({ name: "guest" }) };
});

describe("(when is valid)", () => {
Expand Down Expand Up @@ -62,7 +63,7 @@ describe("steps/save<%= modelNamePluralPascal %>.js", () => {
let mockQueryUpdate;

beforeEach(() => {
actionContext = { <%= modelName %>Id: 1, <%= modelName %>Parameters: { name: "guest1" } };
actionContext = { <%= modelName %>Id: 1, <%= modelName %>Parameters: new <%= modelNamePascal %>({ name: "guest1" }) };
mockQueryUpdate = database.mock
.update({
"name": "guest1",
Expand Down Expand Up @@ -97,7 +98,7 @@ describe("steps/save<%= modelNamePluralPascal %>.js", () => {

describe("(when the new model is invalid)", () => {
beforeEach(() => {
actionContext = { <%= modelName %>Id: 1, <%= modelName %>Parameters: { name: null } };
actionContext = { <%= modelName %>Id: 1, <%= modelName %>Parameters: new <%= modelNamePascal %>({ name: null }) };
});

it("should return with error", done => {
Expand Down

0 comments on commit 2013a50

Please sign in to comment.