-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spec): new specs for create, delete, find, findAll and update us…
…e cases
- Loading branch information
Showing
8 changed files
with
286 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters