recipe-client-addon: Add test for api_url slash handling.

This commit is contained in:
Mike Cooper 2017-05-02 11:16:50 -07:00
Родитель d7801a952a
Коммит db0dd1b32f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 74AB8817639D69C1
1 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -20,7 +20,7 @@ function withServer(server, task) {
);
try {
await task(serverUrl);
await task(serverUrl, preferences);
} finally {
await new Promise(resolve => server.stop(resolve));
}
@ -89,6 +89,37 @@ add_task(withMockApiServer(async function test_getApiUrl(serverUrl) {
equal(recipeListUrl, `${apiBase}/action/`, "Can retrieve action-list URL from API");
}));
add_task(withMockApiServer(async function test_getApiUrlSlashes(serverUrl, preferences) {
const fakeResponse = {
async json() {
return { "test-endpoint": `${serverUrl}/test/` };
},
};
const mockGet = sinon.stub(NormandyApi, "get", async () => fakeResponse)
// without slash
{
NormandyApi.clearIndexCache();
preferences.set("extensions.shield-recipe-client.api_url", `${serverUrl}/api/v1`)
let endpoint = await NormandyApi.getApiUrl("test-endpoint")
equal(endpoint, `${serverUrl}/test/`);
ok(mockGet.calledWithExactly(`${serverUrl}/api/v1/`), "trailing slash was added");
mockGet.reset();
};
// with slash
{
NormandyApi.clearIndexCache();
preferences.set("extensions.shield-recipe-client.api_url", `${serverUrl}/api/v1/`)
let endpoint = await NormandyApi.getApiUrl("test-endpoint")
equal(endpoint, `${serverUrl}/test/`);
ok(mockGet.calledWithExactly(`${serverUrl}/api/v1/`), "existing trailing slash was preserved");
mockGet.reset();
}
mockGet.restore();
}));
add_task(withMockApiServer(async function test_fetchRecipes() {
const recipes = await NormandyApi.fetchRecipes();
equal(recipes.length, 1);