diff --git a/src/commands/new.js b/src/commands/new.js index 532f469..30ab432 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -47,13 +47,13 @@ const questions = [ { type: 'confirm', name: 'graphql', - message: 'Generate graphql layer?', + message: 'Add graphql layer?', default: true, }, { type: 'confirm', name: 'rest', - message: 'Generate rest layer?', + message: 'Add rest layer?', default: true, }, { diff --git a/src/commands/test.js b/src/commands/test.js index fba3786..2eee778 100644 --- a/src/commands/test.js +++ b/src/commands/test.js @@ -19,10 +19,10 @@ const cmd = { for (const spec of specs) { const ret = await spec.run() const usecase = spec.usecase().description - const emoji = (ret) => ret === passed ? green('🗸') : red('•') - toolbox.print.info(`${grey(usecase)} ${emoji(ret)}`) + const result = (ret) => ret === passed ? green('🗸') : red('•') + toolbox.print.info(`${grey(usecase)} ${result(ret)}`) for (const scenario of spec.scenarios) { - toolbox.print.info(` ${grey(scenario.description)} ${emoji(scenario.state)}`) + toolbox.print.info(` ${grey(scenario.description)} ${result(scenario.state)}`) } } diff --git a/src/templates/domain/useCases/tests/create.aloe.test.ejs b/src/templates/domain/useCases/tests/create.aloe.test.ejs index d4560f6..be21912 100644 --- a/src/templates/domain/useCases/tests/create.aloe.test.ejs +++ b/src/templates/domain/useCases/tests/create.aloe.test.ejs @@ -6,7 +6,7 @@ const { herbarium } = require('@herbsjs/herbarium') const create<%- props.name.pascalCase %>Spec = spec({ usecase: create<%- props.name.pascalCase %>, 'Create a new <%- props.name.raw %> when it is valid': scenario({ - 'Given a simple <%- props.name.raw %> is valid': given({ + 'Given a valid <%- props.name.raw %>': given({ request: { <%- props.request.valid %> }, @@ -20,7 +20,7 @@ const create<%- props.name.pascalCase %>Spec = spec({ // when: default when for use case - 'Must return Ok': check((ctx) => { + 'Must run without errors': check((ctx) => { assert.ok(ctx.response.isOk) }), @@ -31,13 +31,27 @@ const create<%- props.name.pascalCase %>Spec = spec({ }), - // 'Do not create a new <%- props.name.raw %> when it is invalid': scenario({}) - // const injection = {} - // const req = { - // <%- props.request.invalid %> - // } - // assert.ok(ret.isErr) - // assert.ok(ret.isInvalidEntityError) + 'Do not create a new <%- props.name.raw %> when it is invalid': scenario({ + 'Given a invalid <%- props.name.raw %>': given({ + request: { + <%- props.request.invalid %> + }, + user: { hasAccess: true }, + injection: { + <%- props.name.camelCase %>Repository: new ( class <%- props.name.pascalCase %>Repository { + async insert(<%- props.name.camelCase %>) { return (<%- props.name.camelCase %>) } + }) + }, + }), + + // when: default when for use case + + 'Must return an error': check((ctx) => { + assert.ok(ctx.response.isErr) + // assert.ok(ret.isInvalidEntityError) + }), + + }), }) module.exports = create<%- props.name.pascalCase %>Spec diff --git a/src/templates/domain/useCases/tests/delete.aloe.test.ejs b/src/templates/domain/useCases/tests/delete.aloe.test.ejs index e69de29..9a5836c 100644 --- a/src/templates/domain/useCases/tests/delete.aloe.test.ejs +++ b/src/templates/domain/useCases/tests/delete.aloe.test.ejs @@ -0,0 +1,62 @@ +const delete<%- props.name.pascalCase %> = require('./delete<%- props.name.pascalCase %>') +const assert = require('assert') +const { spec, scenario, given, check } = require('@herbsjs/aloe') +const { herbarium } = require('@herbsjs/herbarium') + +const delete<%- props.name.pascalCase %>Spec = spec({ + usecase: delete<%- props.name.pascalCase %>, + 'Delete <%- props.name.raw %> if exists': scenario({ + 'Given an existing <%- props.name.raw %>': given({ + request: { + <%- props.request.valid %> + }, + user: { hasAccess: true }, + injection:{ + <%- props.name.pascalCase %>Repository: class <%- props.name.pascalCase %>Repository { + async delete(entity) { return true } + async findByID(id) { return [<%- props.name.pascalCase %>.fromJSON({ id })] } + } + }, + }), + + // when: default when for use case + + 'Must run without errors': check((ctx) => { + assert.ok(ctx.response.isOk) + }), + + 'Must confirm deletion': check((ctx) => { + assert.ok(ctx.response.ok === true) + }) + + }), + + 'Don\'t delete <%- props.name.raw %> if it does not exist': scenario({ + 'Given an empty <%- props.name.raw %> repository': given({ + request: { + <%- props.request.valid %> + }, + user: { hasAccess: true }, + injection:{ + <%- props.name.pascalCase %>Repository: class <%- props.name.pascalCase %>Repository { + async findByID(id) { return [] } + } + }, + }), + + // when: default when for use case + + 'Must return an error': check((ctx) => { + assert.ok(ctx.response.isErr) + assert.ok(ctx.response.isNotFoundError) + }), + }), + }) + +module.exports = delete<%- props.name.pascalCase %>Spec + +//module.exports = +// herbarium.specs +// .add(delete<%- props.name.pascalCase %>Spec, 'Delete<%- props.name.pascalCase %>Spec') +// .metadata({ usecase: 'Delete<%- props.name.pascalCase %>' }) +// .usecase \ No newline at end of file diff --git a/src/templates/domain/useCases/tests/find.aloe.test.ejs b/src/templates/domain/useCases/tests/find.aloe.test.ejs index e69de29..6d21f22 100644 --- a/src/templates/domain/useCases/tests/find.aloe.test.ejs +++ b/src/templates/domain/useCases/tests/find.aloe.test.ejs @@ -0,0 +1,66 @@ +const find<%- props.name.pascalCase %> = require('./find<%- props.name.pascalCase %>') +const assert = require('assert') +const { spec, scenario, given, check } = require('@herbsjs/aloe') +const { herbarium } = require('@herbsjs/herbarium') + +const find<%- props.name.pascalCase %>Spec = spec({ + usecase: find<%- props.name.pascalCase %>, + 'Find a <%- props.name.raw %> when it exists': scenario({ + 'Given an existing <%- props.name.raw %>': given({ + request: { + <%- props.request.valid %> + }, + user: { hasAccess: true }, + injection: { + <%- props.name.pascalCase %>Repository: class <%- props.name.pascalCase %>Repository { + async findByID(id) { + const fake<%- props.name.pascalCase %> = { + <%- props.mock %> + } + return ([<%- props.name.pascalCase %>.fromJSON(fake<%- props.name.pascalCase %>)]) + } + } + }, + }), + + // when: default when for use case + + 'Must run without errors': check((ctx) => { + assert.ok(ctx.response.isOk) + }), + + 'Must return a valid <%- props.name.raw %>': check((ctx) => { + assert.strictEqual(ret.ok.isValid(), true) + }) + + }), + + 'Do not find a <%- props.name.raw %> when it does not exist': scenario({ + 'Given an empty <%- props.name.raw %> repository': given({ + request: { + <%- props.request.valid %> + }, + user: { hasAccess: true }, + injection:{ + <%- props.name.pascalCase %>Repository: class <%- props.name.pascalCase %>Repository { + async findByID(id) { return [] } + } + }, + }), + + // when: default when for use case + + 'Must return an error': check((ctx) => { + assert.ok(ctx.response.isErr) + assert.ok(ret.isNotFoundError) + }), + }), + }) + +module.exports = find<%- props.name.pascalCase %>Spec + +//module.exports = +// herbarium.specs +// .add(find<%- props.name.pascalCase %>Spec, 'Find<%- props.name.pascalCase %>Spec') +// .metadata({ usecase: 'Find<%- props.name.pascalCase %>' }) +// .usecase \ No newline at end of file diff --git a/src/templates/domain/useCases/tests/findAll.aloe.test.ejs b/src/templates/domain/useCases/tests/findAll.aloe.test.ejs index e69de29..1d823c4 100644 --- a/src/templates/domain/useCases/tests/findAll.aloe.test.ejs +++ b/src/templates/domain/useCases/tests/findAll.aloe.test.ejs @@ -0,0 +1,44 @@ +const findAll<%- props.name.pascalCase %> = require('./findAll<%- props.name.pascalCase %>') +const assert = require('assert') +const { spec, scenario, given, check } = require('@herbsjs/aloe') +const { herbarium } = require('@herbsjs/herbarium') + +const findAll<%- props.name.pascalCase %>Spec = spec({ + usecase: findAll<%- props.name.pascalCase %>, + 'Find all <%- props.name.raw %>s': scenario({ + 'Given an existing <%- props.name.raw %>': given({ + request: { limit: 0, offset: 0 }, + user: { hasAccess: true }, + injection: { + <%- props.name.pascalCase %>Repository: class <%- props.name.pascalCase %>Repository { + async findAll(id) { + const fake<%- props.name.pascalCase %> = { + <%- props.mock %> + } + return ([<%- props.name.pascalCase %>.fromJSON(fake<%- props.name.pascalCase %>)]) + } + } + }, + }), + + // when: default when for use case + + 'Must run without errors': check((ctx) => { + assert.ok(ctx.response.isOk) + }), + + 'Must return a list of <%- props.name.raw %>s': check((ctx) => { + assert.strictEqual(ret.ok.length, 1) + }) + + }), + + }) + +module.exports = findAll<%- props.name.pascalCase %>Spec + +//module.exports = +// herbarium.specs +// .add(findAll<%- props.name.pascalCase %>Spec, 'FindAll<%- props.name.pascalCase %>Spec') +// .metadata({ usecase: 'FindAll<%- props.name.pascalCase %>' }) +// .usecase \ No newline at end of file diff --git a/src/templates/domain/useCases/tests/update.aloe.test.ejs b/src/templates/domain/useCases/tests/update.aloe.test.ejs index e69de29..2b6a50b 100644 --- a/src/templates/domain/useCases/tests/update.aloe.test.ejs +++ b/src/templates/domain/useCases/tests/update.aloe.test.ejs @@ -0,0 +1,85 @@ +const update<%- props.name.pascalCase %> = require('./update<%- props.name.pascalCase %>') +const assert = require('assert') +const { spec, scenario, given, check } = require('@herbsjs/aloe') +const { herbarium } = require('@herbsjs/herbarium') + +const update<%- props.name.pascalCase %>Spec = spec({ + usecase: update<%- props.name.pascalCase %>, + 'Update a existing <%- props.name.raw %> when it is valid': scenario({ + 'Given a valid <%- props.name.raw %> and a repository with a existing <%- props.name.raw %>': given({ + request: { + <%- props.request.valid %> + }, + user: { hasAccess: true }, + injection: { + <%- props.name.pascalCase %>Repository: class <%- props.name.pascalCase %>Repository { + async findByID(id) { + const fake<%- props.name.pascalCase %> = { + <%- props.mock %> + } + return ([<%- props.name.pascalCase %>.fromJSON(fake<%- props.name.pascalCase %>)]) + } + async update(id) { return true } + } + }, + }), + + // when: default when for use case + + 'Must run without errors': check((ctx) => { + assert.ok(ctx.response.isOk) + }), + + 'Must confirm update': check((ctx) => { + assert.ok(ctx.response.ok === true) + }) + + }), + + 'Do not update a <%- props.name.raw %> when it is invalid': scenario({ + 'Given a invalid <%- props.name.raw %>': given({ + request: { + <%- props.request.invalid %> + }, + user: { hasAccess: true }, + injection: {}, + }), + + // when: default when for use case + + 'Must return an error': check((ctx) => { + assert.ok(ret.isErr) + assert.ok(ret.isInvalidEntityError) + }), + + }), + + 'Don\'t update <%- props.name.raw %> if it does not exist': scenario({ + 'Given an empty <%- props.name.raw %> repository': given({ + request: { + <%- props.request.valid %> + }, + user: { hasAccess: true }, + injection:{ + <%- props.name.pascalCase %>Repository: class <%- props.name.pascalCase %>Repository { + async findByID(id) { return [] } + } + }, + }), + + // when: default when for use case + + 'Must return an error': check((ctx) => { + assert.ok(ctx.response.isErr) + assert.ok(ret.isNotFoundError) + }), + }), + }) + +module.exports = update<%- props.name.pascalCase %>Spec + +//module.exports = +// herbarium.specs +// .add(update<%- props.name.pascalCase %>Spec, 'Update<%- props.name.pascalCase %>Spec') +// .metadata({ usecase: 'Update<%- props.name.pascalCase %>' }) +// .usecase \ No newline at end of file diff --git a/src/templates/domain/useCases/tests/update.test.ejs b/src/templates/domain/useCases/tests/update.test.ejs index 8519880..2ed822b 100644 --- a/src/templates/domain/useCases/tests/update.test.ejs +++ b/src/templates/domain/useCases/tests/update.test.ejs @@ -5,7 +5,7 @@ const <%- props.name.pascalCase %> = require('../../entities/<%- props.name.pasc describe('Update <%- props.name.raw %>', () => { const authorizedUser = { hasAccess: true } - describe('When a <%- props.name.raw %> is invalid', () => { + describe('When a <%- props.name.raw %> is valid', () => { it('should update <%- props.name.raw %>', async () => { // Given