Open RodolfoSilva opened 3 months ago
@RodolfoSilva, or maintainers, I can make a PR. I've had to solve this a few times and there's a decent pattern that could live as a test implementation or as documentation, or as an igniter module, depending on people's preference
@petermueller could you share this implementation? I think this PR will improve the library DX.
Is there an easy way to mock Goth.fetch!(MyApp.Goth) when running tests? For instance, I want to use the same dummy token when this is used in test mode.
You can use Mock to custom your token response, like:
test "fetch token" do
with_mock Goth, [fetch!: fn _ -> %Goth.Token{token: "XXXXX", type: "X", ...} end] do
assert %Goth.Token{token: "XXXXX", type: "X", ...} == Goth.fetch!(MyApp.Goth)
end
end
Is there an easy way to mock Goth.fetch!(MyApp.Goth) when running tests? For instance, I want to use the same dummy token when this is used in test mode.