-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from MOV-AI/feature/FP-1358-support-different-…
…authentications FP-1358 - Support different authentications
- Loading branch information
Showing
2 changed files
with
83 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Authentication from "./Authentication"; | ||
|
||
const providers = ["internal", "domain1"]; | ||
|
||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
ok: true, | ||
json: () => | ||
Promise.resolve({ | ||
domains: providers, | ||
success: true | ||
}) | ||
}) | ||
); | ||
|
||
beforeEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
test("Get Providers when fetch is successfull", () => { | ||
Authentication.getProviders().then(result => { | ||
expect(result.domains).toEqual(expect.arrayContaining(providers)); | ||
}); | ||
}); | ||
|
||
test("Get Providers when fetch is not successfull", () => { | ||
fetch.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
ok: false | ||
}) | ||
); | ||
Authentication.getProviders().catch(error => | ||
expect(result.domains).toEqual( | ||
expect.arrayContaining([Authentication.DEFAULT_PROVIDER]) | ||
) | ||
); | ||
}); | ||
|
||
test("Get Providers when API is down", () => { | ||
fetch.mockImplementationOnce(() => Promise.reject("API is down")); | ||
Authentication.getProviders().catch(error => | ||
expect(result.domains).toEqual( | ||
expect.arrayContaining([Authentication.DEFAULT_PROVIDER]) | ||
) | ||
); | ||
}); |