-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(actionbasedpolicy): allowing set and get context
- Loading branch information
1 parent
579481c
commit 3420d87
Showing
7 changed files
with
196 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Policy } from './Policy'; | ||
|
||
describe('Policy Class', () => { | ||
it('returns a Policy instance', () => { | ||
expect(new Policy({})).toBeInstanceOf(Policy); | ||
expect(new Policy({ context: { user: { age: 31 } } })).toBeInstanceOf( | ||
Policy | ||
); | ||
}); | ||
|
||
describe('when getContext', () => { | ||
it('returns context attribute', () => { | ||
const context = { user: { age: 31 } }; | ||
expect(new Policy({ context }).getContext()).toBe(context); | ||
}); | ||
}); | ||
|
||
describe('when setContext', () => { | ||
it('sets context attribute', () => { | ||
const context = { user: { age: 31 } }; | ||
const policy = new Policy({}); | ||
policy.setContext(context); | ||
expect(policy.getContext()).toBe(context); | ||
}); | ||
}); | ||
}); |
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,21 @@ | ||
import { PolicyInterface, Context } from './types'; | ||
|
||
class Policy { | ||
protected context: Context; | ||
|
||
constructor({ context }: PolicyInterface) { | ||
if (context) { | ||
this.context = context; | ||
} | ||
} | ||
|
||
setContext(context: Context): void { | ||
this.context = context; | ||
} | ||
|
||
getContext(): Context { | ||
return this.context; | ||
} | ||
} | ||
|
||
export { Policy }; |
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
Oops, something went wrong.