Skip to content

Include context inside uc.authorize() #44

@thgpdr

Description

@thgpdr

Hey guys, I came across a problem theses days, which was:
I needed to test a use case that had an external client call inside authorize(), like calling another micro service to check some user permissions before authorizing the use case execution.

I did realize that I could not inject the external client while testing, because .authorize() do not receive the use case context as a parameter, so I needed to mock the hole external client require or override the ._authorize()

const ucMyBusinessRule = MyBusinessRule()
ucMyBusinessRule._authorize = async () => {
  return { isOk: true }
}

await ucMyBusinessRule.authorize()
const ret = await ucMyBusinessRule.run(parameters)

if (ret.isErr) console.log(ret.err)

const { ruleRet } = ret.ok

expect(ruleRet.isValid()).to.be.true

I dont know if its an real issue and we should add ctx inside the authorize() or that is the expected behavior, since its a convention to not use context inside authorize step. What your thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    More discussion is needed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions