@quorum/schematics
Advanced tools
Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "@quorum/schematics", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "A schematics Library for Quorum", | ||
@@ -5,0 +5,0 @@ "scripts": { |
import { isInt } from 'validator'; | ||
import * as md5 from 'md5'; | ||
import * as metrics from 'datadog-metrics'; | ||
import * as nconf from 'nconf'; | ||
@@ -8,98 +7,57 @@ import { Request as Req } from 'restify'; | ||
import { AuthenticationDatabase as Database } from '../../authentication/authentication.database'; | ||
import { Etag } from 'common/database'; | ||
import { InvalidParameterValueError } from 'common/errors'; | ||
import { Common } from '../shared/common.class'; | ||
import * as errors from 'common/errors/errors.class' | ||
import { Etag } from '../shared/etag.model'; | ||
import { Logger } from 'common/logger'; | ||
import { <%= classify(nameSingular) %>, <%= classify(nameSingular) %>EmbedTypes, <%= classify(nameSingular) %>PatchParameters, <%= classify(nameSingular) %>QueryParameters} from './'; | ||
import { <%= classify(nameSingular) %>} from './<%= nameSingular %>.model'; | ||
import { <%= classify(nameSingular) %>PatchParameters } from './<%= nameSingular %>.patch-model'; | ||
import { <%= classify(nameSingular) %>QueryParameters } from './<%= nameSingular %>.query-model'; | ||
import { ResourceResponse } from '../shared/resource-response.model'; | ||
import * as metrics from 'datadog-metrics'; | ||
export class <%= classify(name) %>{ | ||
export class <%= classify(name) %> { | ||
constructor() { } | ||
private static async addEmbedResources(embedParameter: string, <%=name%>: <%= classify(nameSingular) %>[], userId: string): Promise<<%= classify(nameSingular) %>[]> { | ||
if (embedParameter) { | ||
embedParameter = embedParameter.toUpperCase(); | ||
let promiseArray: any[] = new Array(); | ||
promiseArray.push( | ||
//embedParameter.includes(<%= classify(nameSingular) %>EmbedTypes.LastEvent) ? Events.getEventsForIds(<%=name%>.map((c) => { return c.lastEventId; }), userId) : Promise.resolve({}) | ||
) | ||
await Promise.all(promiseArray).then((results: any[]) => { | ||
results.forEach((result: any, index: number) => { | ||
if (index === 0 && Array.isArray(result)) { | ||
//let events: Event[] = result; | ||
//<%=name%>.forEach((<%=nameSingular%>: <%= classify(nameSingular) %>) => { | ||
// <%=nameSingular%>.lastEvent = events.find((event: Event) => { return event.conversationId === <%=nameSingular%>.id; }); | ||
//}); | ||
} | ||
// TODO: Add code for processing other results once an api is finalized. | ||
}); | ||
}) | ||
} | ||
return <%=name%>; | ||
} | ||
static async get<%= classify(nameSingular) %>(parameters: <%= classify(nameSingular) %>QueryParameters, userId: string): Promise <<%= classify(nameSingular) %>> { | ||
static async get<%= classify(nameSingular) %>(parameters: <%= classify(nameSingular) %>QueryParameters, userId: string): Promise<<%= classify(nameSingular) %>> { | ||
//parameter checks if necessary | ||
//if (!isInt(parameters.id.toString())) throw new InvalidParameterValueError('Id parameter must be a number.'); | ||
const request = new Request(Database.getInstance().pool); | ||
//populate parameters | ||
//request.input('ID', TYPES.Int, id); | ||
let <%=nameSingular%>: <%=classify(nameSingular)%> = await Database.getFirst(request, '<%= getProcedure %>'); | ||
let <%=name%>: <%=classify(nameSingular)%>[] = await <%=classify(name)%>.addEmbedResources(parameters.embed, new Array(<%=nameSingular%>), userId); | ||
return <%=name%>[0]; | ||
return await Common.getFirst(request, '<%= getProcedure %>'); | ||
} | ||
static async get<%= classify(name) %>(parameters: <%= classify(nameSingular) %>QueryParameters, userId: string): Promise <<%= classify(nameSingular) %>[] > { | ||
static async get<%= classify(nameSingular) %>s(parameters: <%= classify(nameSingular) %>QueryParameters, userId: string): Promise<<%= classify(nameSingular) %>[]> { | ||
//parameter checks if necessary | ||
//if (!isInt(parameters.id.toString())) throw new InvalidParameterValueError('Id parameter must be a number.'); | ||
const request = new Request(Database.getInstance().pool); | ||
//populate parameters | ||
//request.input('ID', TYPES.Int, id); | ||
let <%=name%>: <%= classify(nameSingular) %>[] = await Database.get(request, '<%= getProcedure %>'); | ||
return await <%=classify(name)%>.addEmbedResources(parameters.embed, <%=name%>, userId); | ||
return await Common.get(request, '<%= getProcedure %>'); | ||
} | ||
static async get<%=classify(name)%>ForIds(ids: number[], userId: string): Promise<<%= classify(nameSingular) %>[]> { | ||
const request: Request = new Request(Database.getInstance().pool); | ||
request.input('IDs', TYPES.VarChar(250), ids.join(',')); | ||
//request.input('OmitSecurityCheck', TYPES.Bit, true); | ||
//request.input('UserId', TYPES.VarChar(20), userId); | ||
return await Database.get(request, '<%= getProcedure %>'); | ||
} | ||
static async patch<%= classify(nameSingular) %>(resourceId: number, parameters: <%= classify(nameSingular) %>PatchParameters, userId: string): Promise <<%= classify(nameSingular) %>> { | ||
static async patch<%= classify(nameSingular) %>(resourceId: number, parameters: <%= classify(nameSingular) %>PatchParameters, userId: string): Promise<ResourceResponse> { | ||
//parameter checks | ||
//if (!isInt(parameters.id.toString())) throw new InvalidParameterValueError('Id parameter must be a number.'); | ||
const request = new Request(Database.getInstance().pool); | ||
//populate parameters | ||
//request.input('ID', TYPES.Int, id); | ||
//request.input('Json', TYPES.VarChar(1000), JSON.stringify(parameters)); | ||
//request.input('UserID', TYPES.Int, userId); | ||
return await Database.save(request, '<%= getProcedure %>'); | ||
return await Common.save(request, '<%= getProcedure %>'); | ||
} | ||
static async post<%= classify(nameSingular) %>(<%= nameSingular %>: <%= classify(nameSingular) %>, userId: string): Promise <<%= classify(nameSingular) %>> { | ||
static async post<%= classify(nameSingular) %>(<%= nameSingular %>: <%= classify(nameSingular) %>, userId: string): Promise<ResourceResponse> { | ||
//parameter checks | ||
//if (!isInt(parameters.id.toString())) throw new InvalidParameterValueError('Id parameter must be a number.'); | ||
const request = new Request(Database.getInstance().pool); | ||
//populate parameters | ||
//request.input('ID', TYPES.Int, id); | ||
return await Database.save(request, '<%= createProcedure %>'); | ||
return await Common.save(request, '<%= createProcedure %>'); | ||
} | ||
static async put<%= classify(nameSingular) %>(<%= nameSingular %>: <%= classify(nameSingular) %>, userId: string): Promise <<%= classify(nameSingular) %>> { | ||
static async put<%= classify(nameSingular) %>(<%= nameSingular %>: <%= classify(nameSingular) %>, userId: string): Promise<ResourceResponse> { | ||
//parameter checks | ||
//if (!isInt(parameters.id.toString())) throw new InvalidParameterValueError('Id parameter must be a number.'); | ||
var request = new Request(Database.getInstance().pool); | ||
//populate parameters | ||
//request.input('ID', TYPES.Int, id); | ||
return Database.save(request, '<%= updateProcedure %>'); | ||
return Common.save(request, '<%= updateProcedure %>'); | ||
} | ||
static async verifyEtag(resourceId: number, userId: string, etag: string): Promise < Etag > { | ||
static async verifyEtag(resourceId: number, userId: string, etag: string): Promise<Etag> { | ||
let parameters: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters(); | ||
//assign parameters | ||
let <%= nameSingular %>: <%= classify(nameSingular) %> = await <%= classify(name) %>.get<%= classify(nameSingular) %>(parameters, userId); | ||
let newEtag: string = md5(JSON.stringify(<%= nameSingular %>)); | ||
return (newEtag === etag) ? { isMatch: true, resource: <%= nameSingular %>, etag: newEtag } : { isMatch: false, resource: <%= nameSingular %>, etag: newEtag }; | ||
} | ||
//assign parameters | ||
let <%= nameSingular %>: <%= classify(nameSingular) %> = await <%= classify(name) %>.get<%= classify(nameSingular) %>(parameters, userId); | ||
let newEtag: string = md5(JSON.stringify(<%= nameSingular %>)); | ||
return (newEtag === etag) ? { isMatch: true, resource: <%= nameSingular %>, etag: newEtag } : { isMatch: false, resource: <%= nameSingular %>, etag: newEtag }; | ||
} | ||
} |
import { expect } from 'chai'; | ||
import { Request } from 'mssql'; | ||
import * as sinon from 'sinon'; | ||
import { Database } from 'common/database'; | ||
import { <%= classify(nameSingular) %>, <%= classify(name) %>, <%= classify(nameSingular) %>EmbedTypes, <%= classify(nameSingular) %>PatchParameters, <%= classify(nameSingular) %>QueryParameters} from './'; | ||
import { Common } from '../shared/common.class'; | ||
import { <%= classify(name) %>EmbedTypes } from './embed-types.enum'; | ||
import { <%= classify(nameSingular) %>PatchParameters } from './<%= dasherize(nameSingular) %>-patch-model'; | ||
import { <%= classify(name) %>} from './<%= dasherize(name) %>.class'; | ||
import { <%= classify(nameSingular) %>QueryParameters } from './<%= dasherize(nameSingular) %>.query-model'; | ||
import { <%= classify(nameSingular) %> } from './<%= dasherize(nameSingular) %>.model'; | ||
import { expect } from 'chai'; | ||
describe('<%= classify(nameSingular) %>PatchParameters Model', () => { | ||
it('expect to have no properties', () => { | ||
const parameters: <%= classify(nameSingular) %>PatchParameters = new <%= classify(nameSingular) %>PatchParameters(); | ||
expect(parameters).to.be.empty; | ||
const <%= nameSingular %>PatchParameters: <%= classify(nameSingular) %>PatchParameters = new <%= classify(nameSingular) %>PatchParameters(); | ||
expect(<%= nameSingular %>PatchParameters).to.be.empty; | ||
}) | ||
@@ -21,7 +26,7 @@ }) | ||
describe('<%= classify(nameSingular) %> Model', () => { | ||
const properties = ['POPULATE_ME']; | ||
const <%= nameSingular %>Properties = ['POPULATE_ME']; | ||
it('expect to have all properties = null', () => { | ||
const model: <%= classify(nameSingular) %> = new <%= classify(nameSingular) %>(); | ||
expect(model).to.have.all.keys(properties); | ||
const <%= nameSingular %>: <%= classify(nameSingular) %> = new <%= classify(nameSingular) %>(); | ||
expect(<%= nameSingular %>).to.have.all.keys(<%= nameSingular %>Properties); | ||
}) | ||
@@ -31,7 +36,7 @@ }) | ||
describe('<%= classify(nameSingular) %>QueryParameters Model', () => { | ||
const properties = ['POPULATE_ME']; | ||
const <%= nameSingular %>QueryParametersProperties = ['POPULATE_ME']; | ||
it('expect to have all properties with null values', () => { | ||
const parameters: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters(); | ||
expect(parameters).to.have.all.keys(properties); | ||
const <%= nameSingular %>QueryParameters: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters(); | ||
expect(<%= nameSingular %>QueryParameters).to.have.all.keys(<%= nameSingular %>QueryParametersProperties); | ||
}) | ||
@@ -41,66 +46,17 @@ }) | ||
describe('Get<%= classify(nameSingular) %>', () => { | ||
let mssqlRequest: any; | ||
beforeEach(() => { mssqlRequest = sinon.stub(Request.prototype, 'execute'); }); | ||
afterEach(() => { mssqlRequest.restore(); }); | ||
let getFirst: any; | ||
beforeEach(() => { getFirst = sinon.stub(Common, 'getFirst'); }); | ||
afterEach(() => { getFirst.restore(); }); | ||
let resultSet = { | ||
recordsets: [[{ 'JSON_F52E2B61-18A1-11d1-B105-00805F49916B': '[{ "description": "Communicate with customers and co-workers", "icon": "chat", "id": "2", "isBeta": false, "isInternalApp": false, "name": "Communicator", "url": "http://localhost:8087"}]' }]], | ||
recordset: [{ 'JSON_F52E2B61-18A1-11d1-B105-00805F49916B': '[{ "description": "Communicate with customers and co-workers", "icon": "chat", "id": "2", "isBeta": false, "isInternalApp": false, "name": "Communicator", "url": "http://localhost:8087"}]' }], | ||
output: {}, | ||
rowsAffected: [1, 1], | ||
returnValue: 0 | ||
}; | ||
it('should return a <%= nameSingular %>', () => { | ||
let parameters: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters({ id: 338 }); | ||
mssqlRequest.returns(resultSet); | ||
let <%= nameSingular %>QueryParameters: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters({ id: 338 }); | ||
getFirst.returns(new <%= classify(nameSingular) %>({id:'POPULATE_THIS_OBJECT' })); | ||
return <%= classify(name) %>.get<%= classify(nameSingular) %>(parameters, 'POPULATE_ME').then( | ||
(resource: <%= classify(nameSingular) %>) => { | ||
expect(resource).to.be.a('object').to.include({ id: 'POPULATE_THIS_OBJECT' }); | ||
return <%= classify(name) %>.get<%= classify(nameSingular) %>(<%= nameSingular %>QueryParameters, 'POPULATE_ME').then( | ||
(<%= nameSingular %>:<%= classify(nameSingular) %>) => { | ||
expect(<%= nameSingular %>).to.be.a('object').to.include({ id: 'POPULATE_THIS_OBJECT' }); | ||
} | ||
) | ||
}); | ||
}) | ||
describe('Get<%= classify(name) %>', () => { | ||
let mssqlRequest: any; | ||
beforeEach(() => { mssqlRequest = sinon.stub(Request.prototype, 'execute'); }); | ||
afterEach(() => { mssqlRequest.restore(); }); | ||
let resultSet = { | ||
recordsets: [[{ 'JSON_F52E2B61-18A1-11d1-B105-00805F49916B': '[{ "description": "Communicate with customers and co-workers", "icon": "chat", "id": 2, "isBeta": false, "isInternalApp": false, "name": "Communicator", "url": "http://localhost:8087"},{ "description": "Manage your vehicle sales activities and prospects", "icon": "monetization_on", "id": "4", "isBeta": false, "isInternalApp": false, "name": "Sales Planner", "url": "http://localhost:8088/crm/salesplanner"}]' }]], | ||
recordset: [{ 'JSON_F52E2B61-18A1-11d1-B105-00805F49916B': '[{ "description": "Communicate with customers and co-workers", "icon": "chat", "id": 2, "isBeta": false, "isInternalApp": false, "name": "Communicator", "url": "http://localhost:8087"}]' }], | ||
output: {}, | ||
rowsAffected: [1, 1], | ||
returnValue: 0 | ||
}; | ||
describe('Get <%= classify(name) %> with no query parameters', () => { | ||
it('should return 2 <%= name %>', () => { | ||
let parameters: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters(); | ||
mssqlRequest.returns(resultSet); | ||
return <%= classify(name) %>.get<%= classify(nameSingular) %>s(parameters, 'POPULATE_ME').then( | ||
(resource: <%= classify(nameSingular) %>[]) => { | ||
expect(resource).to.have.lengthOf(2); | ||
expect(resource[0]).to.be.a('object').to.include({ id: 'POPULATE_THIS_OBJECT' }); | ||
expect(resource[0]).to.have.all.keys(['POPULATE WITH PROPERTY LIST']); | ||
}) | ||
}) | ||
}) | ||
describe('Get <%= classify(name) %> using query parameters', () => { | ||
it('should return 2 <%= name %>', () => { | ||
let parameters: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters({ isBeta: false }); | ||
mssqlRequest.returns(resultSet); | ||
return <%= classify(name) %>.get<%= classify(nameSingular) %>s(parameters, 'POPULATE_ME').then( | ||
(resource: <%= classify(nameSingular) %>[]) => { | ||
expect(resource).to.have.lengthOf(2); | ||
expect(resource[0]).to.be.a('object').to.include({ id: 'POPULATE_THIS_OBJECT' }); | ||
expect(resource[0]).to.have.all.keys(['POPULATE WITH PROPERTY LIST']); | ||
}) | ||
}) | ||
}) | ||
}) |
export class <%= classify(nameSingular) %> { | ||
id: number = null; | ||
constructor(obj?: any) { | ||
if (obj) Object.assign(this, obj); | ||
constructor(obj?: any){ | ||
if (obj) Object.assign(this,obj); | ||
} | ||
} |
export class <%= classify(nameSingular) %>PatchParameters { | ||
//id: number = null; | ||
constructor(obj ?: any){ | ||
if (obj) Object.assign(this, obj); | ||
constructor(obj?: any){ | ||
if (obj) Object.assign(this,obj); | ||
} | ||
} |
export class <%= classify(nameSingular) %>QueryParameters { | ||
embed: string = null; | ||
id: number = null; | ||
constructor(obj ?: any){ | ||
if (obj) Object.assign(this, obj); | ||
constructor(obj?: any){ | ||
if (obj) Object.assign(this,obj); | ||
} | ||
} |
@@ -8,3 +8,3 @@ import { StoredProcedure } from "common/message-broker"; | ||
import { RequestTypes } from "common/message-broker"; | ||
import { <%= classify(nameSingular) %>QueryParameters } from 'api/associates' | ||
import { <%= classify(nameSingular) %>QueryParameters } from './<%=dasherize(nameSingular)%>.query-model'; | ||
import { <%= classify(nameSingular) %> } from './<%=dasherize(nameSingular)%>.model'; | ||
@@ -15,30 +15,28 @@ import { v1 as uuid } from 'uuid'; | ||
static create<%= classify(nameSingular) %>(<%= nameSingular %> : <%= classify(nameSingular) %>, routingDetails: any): BrokerMessage { | ||
let brokerMessage: BrokerMessage; | ||
static create<%= classify(nameSingular) %>(<%= nameSingular %> : <%= classify(nameSingular) %>, routingDetails: any): BrokerMessagePayload { | ||
let brokerMessagePayload: BrokerMessagePayload; | ||
if (routingDetails.version === 1) { | ||
let sp = new StoredProcedure('<%= createProcedure %>'); | ||
//Populate parameers here | ||
//Populate parameters here | ||
brokerMessage = new BrokerMessage(new BrokerMessageHeaders(routingDetails.server, routingDetails.dsn, 'api.create<%= classify(nameSingular) %>')); | ||
brokerMessage.payload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
brokerMessagePayload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
} | ||
return brokerMessage; | ||
return brokerMessagePayload; | ||
} | ||
static get<%= classify(nameSingular) %>(id: string, routingDetails: any): BrokerMessage { | ||
let brokerMessage: BrokerMessage; | ||
static get<%= classify(nameSingular) %>(id: string, routingDetails: any): BrokerMessagePayload { | ||
let brokerMessagePayload: BrokerMessagePayload; | ||
if (routingDetails.version === 1) { | ||
let sp = new StoredProcedure('<%= getProcedure %>'); | ||
//Populate parameers here | ||
//Populate parameters here | ||
brokerMessage = new BrokerMessage(new BrokerMessageHeaders(routingDetails.server, routingDetails.dsn, 'api.get<%= classify(nameSingular) %>')); | ||
brokerMessage.payload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
brokerMessagePayload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
} | ||
return brokerMessage; | ||
return brokerMessagePayload; | ||
} | ||
static get<%= classify(name) %>(params: <%= classify(nameSingular) %>QueryParameters, routingDetails: any): BrokerMessage { | ||
let brokerMessage: BrokerMessage; | ||
static get<%= classify(name) %>(params: <%= classify(nameSingular) %>QueryParameters, routingDetails: any): BrokerMessagePayload { | ||
let brokerMessagePayload: BrokerMessagePayload; | ||
if (routingDetails.version === 1) { | ||
@@ -49,20 +47,17 @@ let sp = new StoredProcedure('<%= getProcedure %>'); | ||
brokerMessage = new BrokerMessage(new BrokerMessageHeaders(routingDetails.server, routingDetails.dsn, 'api.get<%= classify(name) %>')); | ||
brokerMessage.payload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
brokerMessagePayload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
} | ||
return brokerMessage; | ||
return brokerMessagePayload; | ||
} | ||
static update<%= classify(nameSingular) %>(<%= nameSingular %> : <%= classify(nameSingular) %>, routingDetails: any): BrokerMessage { | ||
let brokerMessage: BrokerMessage; | ||
static update<%= classify(nameSingular) %>(<%= nameSingular %> : <%= classify(nameSingular) %>, routingDetails: any): BrokerMessagePayload { | ||
let brokerMessagePayload: BrokerMessagePayload; | ||
if (routingDetails.version === 1) { | ||
let sp = new StoredProcedure('<%= updateProcedure %>'); | ||
//Populate parameers here | ||
brokerMessage = new BrokerMessage(new BrokerMessageHeaders(routingDetails.server, routingDetails.dsn, 'api.update<%= classify(name) %>')); | ||
brokerMessage.payload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
//Populate parameters here | ||
brokerMessagePayload = new BrokerMessagePayload(RequestTypes.StoredProcedure, sp, uuid()); | ||
} | ||
return brokerMessage; | ||
return brokerMessagePayload; | ||
} | ||
} |
@@ -22,3 +22,3 @@ import { StoredProcedure } from "common/message-broker"; | ||
let createResult: BrokerMessage | ||
let eventHandler: EventHandler; | ||
const eventHandler: EventHandler = new EventHandler(null, null); | ||
let response: BrokerMessage; | ||
@@ -38,11 +38,16 @@ let <%= nameSingular %> : <%= classify(nameSingular) %> ; | ||
describe('<%= classify(routeParent) %>.create<%= classify(nameSingular) %>', () => { | ||
create<%= classify(nameSingular) %> = new <%= classify(nameSingular) %>(); | ||
before((done) => { | ||
createResult = <%= classify(name) %>.create<%= classify(nameSingular) %>(create<%= classify(nameSingular) %> , { server: process.env.TESTING_SERVER, dsn: process.env.TEMP_DB, version: 1 }); | ||
result = new BrokerMessage( | ||
new BrokerMessageHeaders(process.env.TESTING_SERVER, process.env.TEMP_DB, 'api.create<%= classify(nameSingular) %>') | ||
); | ||
result.payload = <%= classify(nameSingular) %>s.create<%= classify(nameSingular) %>(<%= nameSingular %> , { | ||
server: process.env.TESTING_SERVER, | ||
dsn: process.env.TEMP_DB, | ||
version: 1 | ||
}); | ||
this.eventHandler = new EventHandler(null, null); | ||
this.eventHandler.handleRequest(createResult) | ||
eventHandler.handleRequest(result) | ||
.then((res: BrokerMessage) => { | ||
response = res; | ||
<%= nameSingular %> = response.payload.recordsets[0][0]; | ||
done(); | ||
@@ -65,11 +70,14 @@ }) | ||
before((done) => { | ||
result = <%= classify(name) %>.get<%= classify(nameSingular) %>(create<%= classify(nameSingular) %>.id, { server: process.env.TESTING_SERVER, dsn: process.env.TEMP_DB, version: 1 }); | ||
this.eventHandler = new EventHandler(null, null); | ||
this.eventHandler.handleRequest(result) | ||
.then((res: BrokerMessage) => { | ||
response = res; | ||
<%= nameSingular %> = response.payload.recordsets[0][0]; | ||
done(); | ||
}); | ||
result = new BrokerMessage( | ||
new BrokerMessageHeaders(process.env.TESTING_SERVER, process.env.TEMP_DB, 'api.get<%= classify(nameSingular) %>') | ||
); | ||
result.payload = <%= classify(nameSingular) %>s.get<%= classify(nameSingular) %>(<%= nameSingular %>.id, { | ||
server: process.env.TESTING_SERVER, | ||
dsn: process.env.TEMP_DB, | ||
version: 1 | ||
}); | ||
eventHandler.handleRequest(result).then((res: BrokerMessage) => { | ||
response = res; | ||
done(); | ||
}); | ||
}); | ||
@@ -82,3 +90,3 @@ | ||
it('it should have all the correct properties', () => { | ||
expect(<%= nameSingular %>).to.have.all.keys([]); | ||
expect(response.payload.recordsets[0][0]).to.have.all.keys(<%= nameSingular %>); | ||
}); | ||
@@ -91,11 +99,15 @@ }); | ||
//modify <%= nameSingular %> here | ||
result = <%= classify(name) %>.update<%= classify(nameSingular) %>(<%= nameSingular %>, { server: process.env.TESTING_SERVER, dsn: process.env.TEMP_DB, version: 1 }); | ||
this.eventHandler = new EventHandler(null, null); | ||
this.eventHandler.handleRequest(result) | ||
.then((res: BrokerMessage) => { | ||
response = res; | ||
<%= nameSingular %> = response.payload.recordsets[0][0]; | ||
done(); | ||
}); | ||
result = new BrokerMessage( | ||
new BrokerMessageHeaders(process.env.TESTING_SERVER, process.env.TEMP_DB, 'api.update<%= classify(nameSingular) %>') | ||
); | ||
result.payload = <%= classify(nameSingular) %>s.updateServiceGroupRate(<%= nameSingular %>, { | ||
server: process.env.TESTING_SERVER, | ||
dsn: process.env.TEMP_DB, | ||
version: 1 | ||
}); | ||
eventHandler.handleRequest(result).then((res: BrokerMessage) => { | ||
response = res; | ||
done(); | ||
}); | ||
}); | ||
@@ -109,3 +121,3 @@ | ||
it('it should have all the correct properties', () => { | ||
expect(<%= nameSingular %>).to.have.all.keys([]); | ||
expect(response.payload.recordsets[0][0]).to.have.all.keys(<%= nameSingular %>); | ||
}); | ||
@@ -112,0 +124,0 @@ }); |
@@ -16,16 +16,13 @@ import { StoredProcedure } from "common/message-broker"; | ||
let <%= nameSingular %>: <%= classify(nameSingular) %> = new <%= classify(nameSingular) %>(); | ||
const result: BrokerMessage = <%= classify(name) %>.create<%= classify(nameSingular) %>(<%= nameSingular %>, { server: 'test', dsn: 'test', version: 1 }); | ||
const result: BrokerMessagePayload = <%= classify(name) %>.create<%= classify(nameSingular) %>(<%= nameSingular %>, { server: 'test', dsn: 'test', version: 1 }); | ||
it('it should be a stored procedure', () => { | ||
expect(result.payload.requestType).to.equal(RequestTypes.StoredProcedure); | ||
expect(result.requestType).to.equal(RequestTypes.StoredProcedure); | ||
}); | ||
it('Stored Procedure should be called <%= createProcedure %>', () => { | ||
expect(result.payload.request.name).to.equal('<%= createProcedure %>'); | ||
expect(result.request.name).to.equal('<%= createProcedure %>'); | ||
}); | ||
it('it should have replace_me parameters', () => { | ||
expect(result.payload.request.parameters.length).to.equal(0); | ||
expect(result.request.parameters.length).to.equal(0); | ||
}); | ||
it('its return event should be api.create<%= classify(nameSingular) %>', () => { | ||
expect(result.headers.returnEvent).to.equal('api.create<%= classify(nameSingular) %>'); | ||
}); | ||
}); | ||
@@ -36,15 +33,12 @@ }); | ||
describe('Version 1', () => { | ||
const result: BrokerMessage = <%= classify(name) %>.get<%= classify(nameSingular) %>('1', { server: 'test', dsn: 'test', version: 1 }); | ||
const result: BrokerMessagePayload = <%= classify(name) %>.get<%= classify(nameSingular) %>('1', { server: 'test', dsn: 'test', version: 1 }); | ||
it('it should be a stored procedure', () => { | ||
expect(result.payload.requestType).to.equal(RequestTypes.StoredProcedure); | ||
expect(result.requestType).to.equal(RequestTypes.StoredProcedure); | ||
}); | ||
it('Stored Procedure should be called <%= getProcedure %>', () => { | ||
expect(result.payload.request.name).to.equal('<%= getProcedure %>'); | ||
expect(result.request.name).to.equal('<%= getProcedure %>'); | ||
}); | ||
it('it should have X parameter', () => { | ||
expect(result.payload.request.parameters.length).to.equal(0); | ||
expect(result.request.parameters.length).to.equal(0); | ||
}); | ||
it('its return event should be api.get<%= classify(nameSingular) %>', () => { | ||
expect(result.headers.returnEvent).to.equal('api.get<%= classify(nameSingular) %>'); | ||
}); | ||
}); | ||
@@ -56,15 +50,12 @@ }); | ||
const params: <%= classify(nameSingular) %>QueryParameters = new <%= classify(nameSingular) %>QueryParameters(); | ||
const result: BrokerMessage = <%= classify(name) %>.get<%= classify(name) %>(params, { server: 'test', dsn: 'test', version: 1 }); | ||
const result: BrokerMessagePayload = <%= classify(name) %>.get<%= classify(name) %>(params, { server: 'test', dsn: 'test', version: 1 }); | ||
it('it should be a stored procedure', () => { | ||
expect(result.payload.requestType).to.equal(RequestTypes.StoredProcedure); | ||
expect(result.requestType).to.equal(RequestTypes.StoredProcedure); | ||
}); | ||
it('Stored Procedure should be called <%= getProcedure %>', () => { | ||
expect(result.payload.request.name).to.equal('<%= getProcedure %>'); | ||
expect(result.request.name).to.equal('<%= getProcedure %>'); | ||
}); | ||
it('it should have X parameters', () => { | ||
expect(result.payload.request.parameters.length).to.equal(0); | ||
expect(result.request.parameters.length).to.equal(0); | ||
}); | ||
it('its return event should be api.get<%= classify(name) %>', () => { | ||
expect(result.headers.returnEvent).to.equal('api.get<%= classify(name) %>'); | ||
}); | ||
}); | ||
@@ -78,16 +69,13 @@ }); | ||
}; | ||
const result: BrokerMessage = <%= classify(name) %>.update<%= classify(nameSingular) %>(<%= nameSingular %>, { server: 'test', dsn: 'test', version: 1 }); | ||
const result: BrokerMessagePayload = <%= classify(name) %>.update<%= classify(nameSingular) %>(<%= nameSingular %>, { server: 'test', dsn: 'test', version: 1 }); | ||
it('it should be a stored procedure', () => { | ||
expect(result.payload.requestType).to.equal(RequestTypes.StoredProcedure); | ||
expect(result.requestType).to.equal(RequestTypes.StoredProcedure); | ||
}); | ||
it('Stored Procedure should be called <%= updateProcedure %>', () => { | ||
expect(result.payload.request.name).to.equal('<%= updateProcedure %>'); | ||
expect(result.request.name).to.equal('<%= updateProcedure %>'); | ||
}); | ||
it('it should have X parameters', () => { | ||
expect(result.payload.request.parameters.length).to.equal(0); | ||
expect(result.request.parameters.length).to.equal(0); | ||
}); | ||
it('its return event should be api.update<%= classify(name) %>', () => { | ||
expect(result.headers.returnEvent).to.equal('api.update<%= classify(name) %>'); | ||
}); | ||
}); | ||
}); |
@@ -24,2 +24,3 @@ "use strict"; | ||
options.updateProcedure = prompt('What is the update procedure? '); | ||
options.patchProcedure = prompt('What is the patch procedure? '); | ||
options.tableName = prompt('What is the table name? '); | ||
@@ -26,0 +27,0 @@ const templateSource = schematics_2.apply(schematics_2.url(filesFolder), [ |
Sorry, the diff of this file is not supported yet
29136
20
539