Skip to content

Commit 53872f5

Browse files
committed
Updated tests for non-prod changes
* Updated getCanonicalSubscriptionUrls tests * localhost and staging only support one domain * Fixes 2 tests that PR #620 broke https://travis-ci.org/github/OneSignal/OneSignal-Website-SDK/builds/672001235?utm_source=github_status
1 parent c34ec83 commit 53872f5

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

test/unit/managers/AltOriginManager.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@ test(`should get correct canonical subscription URL for development environment`
1212
config.httpUseOneSignalCom = true;
1313

1414
const devUrlsOsTcDomain = AltOriginManager.getCanonicalSubscriptionUrls(config, EnvironmentKind.Development);
15-
t.is(devUrlsOsTcDomain.length, 2);
15+
t.is(devUrlsOsTcDomain.length, 1);
1616
t.is(devUrlsOsTcDomain[0].host, new URL('https://test.localhost:3001').host);
17-
t.is(devUrlsOsTcDomain[1].host, new URL('https://test.os.tc:3001').host);
1817

1918
config.httpUseOneSignalCom = false;
2019

2120
const devUrls = AltOriginManager.getCanonicalSubscriptionUrls(config, EnvironmentKind.Development);
2221
t.is(devUrls.length, 1);
23-
t.is(devUrls[0].host, new URL('https://test.os.tc:3001').host);
22+
t.is(devUrls[0].host, new URL('https://test.localhost:3001').host);
2423
});
2524

2625
test(`should get correct canonical subscription URL for staging environment`, async t => {
26+
const stagingDomain = "staging.onesignal.com";
27+
(<any>global).__API_ORIGIN__ = stagingDomain;
2728
const config = TestEnvironment.getFakeAppConfig();
2829
config.subdomain = 'test';
2930
config.httpUseOneSignalCom = true;
3031

3132
const browser = await TestEnvironment.stubDomEnvironment();
32-
browser.changeURL(window, "http://staging-01.onesignal.com");
33+
browser.changeURL(window, `http://${stagingDomain}`);
3334

3435
const stagingUrlsOsTcDomain = AltOriginManager.getCanonicalSubscriptionUrls(config, EnvironmentKind.Staging);
35-
t.is(stagingUrlsOsTcDomain.length, 2);
36-
t.is(stagingUrlsOsTcDomain[0].host, new URL('https://test.staging-01.onesignal.com').host);
37-
t.is(stagingUrlsOsTcDomain[1].host, new URL('https://test.os.tc').host);
36+
t.is(stagingUrlsOsTcDomain.length, 1);
37+
t.is(stagingUrlsOsTcDomain[0].host, new URL(`https://test.${stagingDomain}`).host);
3838

39+
// staging does not support an alt domain so it should be the same.
3940
config.httpUseOneSignalCom = false;
40-
4141
const stagingUrls = AltOriginManager.getCanonicalSubscriptionUrls(config, EnvironmentKind.Staging);
4242
t.is(stagingUrls.length, 1);
43-
t.is(stagingUrls[0].host, new URL('https://test.os.tc').host);
43+
t.is(stagingUrls[0].host, new URL(`https://test.${stagingDomain}`).host);
4444
});
4545

4646
test(`should get correct canonical subscription URL for production environment`, async t => {
@@ -50,8 +50,8 @@ test(`should get correct canonical subscription URL for production environment`,
5050

5151
const prodUrlsOsTcDomain = AltOriginManager.getCanonicalSubscriptionUrls(config, EnvironmentKind.Production);
5252
t.is(prodUrlsOsTcDomain.length, 2);
53-
t.is(prodUrlsOsTcDomain[0].host, new URL('https://test.onesignal.com').host);
54-
t.is(prodUrlsOsTcDomain[1].host, new URL('https://test.os.tc').host);
53+
t.is(prodUrlsOsTcDomain[0].host, new URL('https://test.os.tc').host);
54+
t.is(prodUrlsOsTcDomain[1].host, new URL('https://test.onesignal.com').host);
5555

5656
config.httpUseOneSignalCom = false;
5757

test/unit/modules/sdkEnvironment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ test('API URL should be valid for development environment', async t => {
7171
});
7272

7373
test('API URL should be valid for staging environment', async t => {
74+
const browser = await TestEnvironment.stubDomEnvironment();
75+
browser.changeURL(window, "https://localhost");
7476
const expectedUrl = `https://${window.location.host}/api/v1`;
7577
t.is(SdkEnvironment.getOneSignalApiUrl(EnvironmentKind.Staging).toString(), expectedUrl);
7678
});

0 commit comments

Comments
 (0)