-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Context bindings - Finding bindings" #61
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
56 changes: 0 additions & 56 deletions
56
packages/loopback/test/acceptance/context-bindings/find/basic-usage.feature.md
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
packages/loopback/test/acceptance/context-bindings/finding-bindings.feature.md
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,52 @@ | ||
# Feature: Context Binding - Finding bindings | ||
|
||
## Scenario: Finding all bindings | ||
|
||
- Given a context | ||
- And a binding with key `foo` bound to the value `bar` | ||
- And another binding with key `bat` bound to the value `baz` | ||
- When I find all bindings | ||
- Then I get a list of all bindings | ||
|
||
```ts | ||
// create a container for bindings | ||
const ctx = new Context(); | ||
|
||
// creating two simple bindings | ||
ctx.bind('foo').to('bar'); | ||
ctx.bind('baz').to('qux'); | ||
|
||
// find all bindings | ||
const bindings = ctx.find(); | ||
|
||
const keys = bindings.map(binding => { | ||
return binding.key; | ||
}); | ||
console.log(keys); // => ['foo', 'baz'] | ||
``` | ||
|
||
## Scenario: Finding bindings by pattern | ||
|
||
- Given a context | ||
- And a binding with key `my.foo` bound to the value `bar` | ||
- And another binding with key `my.baz` bound to the value `qux` | ||
- When I find all bindings using a pattern | ||
- Then I get a list of all bindings matching the pattern | ||
|
||
```ts | ||
// create a container for bindings | ||
const ctx = new Context({ | ||
delimiter: '.' // default | ||
}); | ||
|
||
// creating three simple bindings | ||
ctx.bind('my.foo').to('bar'); | ||
ctx.bind('my.baz').to('qux'); | ||
ctx.bind('ur.quux').to('quuz'); | ||
|
||
// find all bindings | ||
const bindings = ctx.find('my.*'); | ||
|
||
const keys = bindings.map(binding => binding.key) | ||
console.log(keys); // => ['my.foo', 'my.baz'] | ||
``` |
55 changes: 55 additions & 0 deletions
55
packages/loopback/test/acceptance/context-bindings/finding-bindings.ts
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,55 @@ | ||
// Copyright IBM Corp. 2013,2017. All Rights Reserved. | ||
// Node module: loopback | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {expect} from '@loopback/testlab'; | ||
import * as util from 'loopback/test/support/util'; | ||
|
||
describe('Context bindings - Finding bindings', () => { | ||
let ctx; | ||
|
||
describe('Finding all binding', () => { | ||
before('given a context', createContext); | ||
before('with two simple bindings', () => { | ||
createBinding('foo', 'bar'); | ||
createBinding('baz', 'qux'); | ||
}); | ||
|
||
describe('when I find all bindings', () => { | ||
it('returns all bindings', () => { | ||
const bindings = ctx.find(); | ||
const keys = bindings.map(binding => { | ||
return binding.key; | ||
}); | ||
expect(keys).to.include('foo', 'baz'); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('Finding bindings by pattern', () => { | ||
before('given a context', createContext); | ||
before('with namespaced bindings', () => { | ||
createBinding('my.foo', 'bar'); | ||
createBinding('my.baz', 'qux'); | ||
createBinding('ur.quux', 'quuz'); | ||
}); | ||
|
||
describe('when I find all bindings using a pattern', () => { | ||
it('returns all bindings matching the pattern', () => { | ||
const bindings = ctx.find('my.*'); | ||
const keys = bindings.map(binding => binding.key); | ||
expect(keys).to.include('my.foo', 'my.baz'); | ||
expect(keys).to.not.include('ur.quux'); | ||
}); | ||
}); | ||
}); | ||
|
||
function createContext() { | ||
ctx = util.getContext(); | ||
} | ||
function createBinding(key, value) { | ||
ctx.bind(key).to(value); | ||
} | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should support
string|Symbol
...can do in another PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created follow up issue at #67, we can discuss priority during planning.