allow domain sharding in frontend (#5039)

This commit is contained in:
Grace Guo
2018-11-30 10:30:04 -08:00
committed by GitHub
parent 20e1ac6242
commit 8e14e0bd67
7 changed files with 148 additions and 4 deletions

View File

@@ -1,5 +1,8 @@
import sinon from 'sinon';
import URI from 'urijs';
import { getExploreUrlAndPayload, getExploreLongUrl } from '../../../src/explore/exploreUtils';
import * as hostNamesConfig from '../../../src/utils/hostNamesConfig';
describe('exploreUtils', () => {
const location = window.location;
@@ -128,6 +131,71 @@ describe('exploreUtils', () => {
});
});
describe('domain sharding', () => {
let stub;
const availableDomains = [
'http://localhost/',
'domain1.com', 'domain2.com', 'domain3.com',
];
beforeEach(() => {
stub = sinon.stub(hostNamesConfig, 'availableDomains').value(availableDomains);
});
afterEach(() => {
stub.restore();
});
it('generate url to different domains', () => {
let url = getExploreUrlAndPayload({
formData,
endpointType: 'json',
allowDomainSharding: true,
}).url;
expect(url).toMatch(availableDomains[0]);
url = getExploreUrlAndPayload({
formData,
endpointType: 'json',
allowDomainSharding: true,
}).url;
expect(url).toMatch(availableDomains[1]);
url = getExploreUrlAndPayload({
formData,
endpointType: 'json',
allowDomainSharding: true,
}).url;
expect(url).toMatch(availableDomains[2]);
url = getExploreUrlAndPayload({
formData,
endpointType: 'json',
allowDomainSharding: true,
}).url;
expect(url).toMatch(availableDomains[3]);
// circle back to first available domain
url = getExploreUrlAndPayload({
formData,
endpointType: 'json',
allowDomainSharding: true,
}).url;
expect(url).toMatch(availableDomains[0]);
});
it('not generate url to different domains without flag', () => {
let csvURL = getExploreUrlAndPayload({
formData,
endpointType: 'csv',
}).url;
expect(csvURL).toMatch(availableDomains[0]);
csvURL = getExploreUrlAndPayload({
formData,
endpointType: 'csv',
}).url;
expect(csvURL).toMatch(availableDomains[0]);
});
});
describe('getExploreLongUrl', () => {
it('generates proper base url with form_data', () => {
compareURI(