Skip to content

Commit e00c05e

Browse files
committed
test(remoteConfig): move non-native tests to jest
1 parent d0d9bd8 commit e00c05e

File tree

2 files changed

+115
-100
lines changed

2 files changed

+115
-100
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
import { firebase } from '../lib';
18+
19+
describe('remoteConfig()', function () {
20+
describe('namespace', function () {
21+
it('accessible from firebase.app()', function () {
22+
const app = firebase.app();
23+
expect(app.remoteConfig()).toBeDefined();
24+
expect(app.remoteConfig().app).toEqual(app);
25+
});
26+
27+
it('supports multiple apps', async function () {
28+
expect(firebase.remoteConfig().app.name).toEqual('[DEFAULT]');
29+
expect(firebase.app('secondaryFromNative').remoteConfig().app.name).toEqual(
30+
'secondaryFromNative',
31+
);
32+
});
33+
});
34+
35+
describe('statics', function () {
36+
it('LastFetchStatus', function () {
37+
expect(firebase.remoteConfig.LastFetchStatus).toBeDefined();
38+
expect(firebase.remoteConfig.LastFetchStatus.FAILURE).toEqual('failure');
39+
expect(firebase.remoteConfig.LastFetchStatus.SUCCESS).toEqual('success');
40+
expect(firebase.remoteConfig.LastFetchStatus.NO_FETCH_YET).toEqual('no_fetch_yet');
41+
expect(firebase.remoteConfig.LastFetchStatus.THROTTLED).toEqual('throttled');
42+
});
43+
44+
it('ValueSource', function () {
45+
expect(firebase.remoteConfig.ValueSource).toBeDefined();
46+
expect(firebase.remoteConfig.ValueSource.REMOTE).toEqual('remote');
47+
expect(firebase.remoteConfig.ValueSource.STATIC).toEqual('static');
48+
expect(firebase.remoteConfig.ValueSource.DEFAULT).toEqual('default');
49+
});
50+
});
51+
52+
describe('fetch()', function () {
53+
it('it throws if expiration is not a number', function () {
54+
expect(() => {
55+
// @ts-ignore - incorrect argument on purpose to check validation
56+
firebase.remoteConfig().fetch('foo');
57+
}).toThrow('must be a number value');
58+
});
59+
});
60+
61+
describe('setConfigSettings()', function () {
62+
it('it throws if arg is not an object', async function () {
63+
expect(() => {
64+
// @ts-ignore - incorrect argument on purpose to check validation
65+
firebase.remoteConfig().setConfigSettings('not an object');
66+
}).toThrow('must set an object');
67+
});
68+
69+
it('throws if minimumFetchIntervalMillis is not a number', async function () {
70+
expect(() => {
71+
// @ts-ignore - incorrect argument on purpose to check validation
72+
firebase.remoteConfig().setConfigSettings({ minimumFetchIntervalMillis: 'potato' });
73+
}).toThrow('must be a number type in milliseconds.');
74+
});
75+
76+
it('throws if fetchTimeMillis is not a number', function () {
77+
expect(() => {
78+
// @ts-ignore - incorrect argument on purpose to check validation
79+
firebase.remoteConfig().setConfigSettings({ fetchTimeMillis: 'potato' });
80+
}).toThrow('must be a number type in milliseconds.');
81+
});
82+
});
83+
84+
// TODO set up a mock for getAll from issue 5854 and probe if result is empty
85+
// describe('getAll() with remote', function () {
86+
// it('should return an object of all available values', function () {
87+
// const config = firebase.remoteConfig().getAll();
88+
// config.number.asNumber().should.equal(1337);
89+
// config.number.getSource().should.equal('remote');
90+
// // firebase console stores as a string
91+
// config.float.asNumber().should.equal(123.456);
92+
// config.float.getSource().should.equal('remote');
93+
// config.prefix_1.asNumber().should.equal(1);
94+
// config.prefix_1.getSource().should.equal('remote');
95+
// });
96+
// });
97+
98+
describe('setDefaults()', function () {
99+
it('it throws if defaults object not provided', function () {
100+
expect(() => {
101+
// @ts-ignore - incorrect argument on purpose to check validation
102+
firebase.remoteConfig().setDefaults('not an object');
103+
}).toThrow('must be an object.');
104+
});
105+
});
106+
107+
describe('setDefaultsFromResource()', function () {
108+
it('throws if resourceName is not a string', function () {
109+
expect(() => {
110+
// @ts-ignore - incorrect argument on purpose to check validation
111+
firebase.remoteConfig().setDefaultsFromResource(1337);
112+
}).toThrow('must be a string value');
113+
});
114+
});
115+
});

packages/remote-config/e2e/config.e2e.js

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,6 @@
1616
*/
1717

1818
describe('remoteConfig()', function () {
19-
describe('namespace', function () {
20-
it('accessible from firebase.app()', function () {
21-
const app = firebase.app();
22-
should.exist(app.remoteConfig);
23-
app.remoteConfig().app.should.equal(app);
24-
});
25-
26-
it('supports multiple apps', async function () {
27-
firebase.firestore().app.name.should.equal('[DEFAULT]');
28-
29-
firebase
30-
.firestore(firebase.app('secondaryFromNative'))
31-
.app.name.should.equal('secondaryFromNative');
32-
33-
firebase
34-
.app('secondaryFromNative')
35-
.remoteConfig()
36-
.app.name.should.equal('secondaryFromNative');
37-
});
38-
});
39-
40-
describe('statics', function () {
41-
it('LastFetchStatus', function () {
42-
firebase.remoteConfig.LastFetchStatus.should.be.an.Object();
43-
firebase.remoteConfig.LastFetchStatus.FAILURE.should.equal('failure');
44-
firebase.remoteConfig.LastFetchStatus.SUCCESS.should.equal('success');
45-
firebase.remoteConfig.LastFetchStatus.NO_FETCH_YET.should.equal('no_fetch_yet');
46-
firebase.remoteConfig.LastFetchStatus.THROTTLED.should.equal('throttled');
47-
});
48-
49-
it('ValueSource', function () {
50-
firebase.remoteConfig.ValueSource.should.be.an.Object();
51-
firebase.remoteConfig.ValueSource.REMOTE.should.equal('remote');
52-
firebase.remoteConfig.ValueSource.STATIC.should.equal('static');
53-
firebase.remoteConfig.ValueSource.DEFAULT.should.equal('default');
54-
});
55-
});
56-
5719
describe('fetch()', function () {
5820
it('with expiration provided', async function () {
5921
const date = Date.now() - 30000;
@@ -73,15 +35,6 @@ describe('remoteConfig()', function () {
7335
it('without expiration provided', function () {
7436
return firebase.remoteConfig().fetch();
7537
});
76-
it('it throws if expiration is not a number', function () {
77-
try {
78-
firebase.remoteConfig().fetch('foo');
79-
return Promise.reject(new Error('Did not throw'));
80-
} catch (error) {
81-
error.message.should.containEql('must be a number value');
82-
return Promise.resolve();
83-
}
84-
});
8538
});
8639

8740
describe('fetchAndActivate()', function () {
@@ -114,50 +67,17 @@ describe('remoteConfig()', function () {
11467
});
11568

11669
describe('setConfigSettings()', function () {
117-
it('it throws if arg is not an object', async function () {
118-
try {
119-
firebase.remoteConfig().setConfigSettings('not an object');
120-
121-
return Promise.reject(new Error('Did not throw'));
122-
} catch (error) {
123-
error.message.should.containEql('must set an object');
124-
return Promise.resolve();
125-
}
126-
});
127-
12870
it('minimumFetchIntervalMillis sets correctly', async function () {
12971
await firebase.remoteConfig().setConfigSettings({ minimumFetchIntervalMillis: 3000 });
13072

13173
firebase.remoteConfig().settings.minimumFetchIntervalMillis.should.be.equal(3000);
13274
});
13375

134-
it('throws if minimumFetchIntervalMillis is not a number', async function () {
135-
try {
136-
firebase.remoteConfig().setConfigSettings({ minimumFetchIntervalMillis: 'potato' });
137-
138-
return Promise.reject(new Error('Did not throw'));
139-
} catch (error) {
140-
error.message.should.containEql('must be a number type in milliseconds.');
141-
return Promise.resolve();
142-
}
143-
});
144-
14576
it('fetchTimeMillis sets correctly', async function () {
14677
await firebase.remoteConfig().setConfigSettings({ fetchTimeMillis: 3000 });
14778

14879
firebase.remoteConfig().settings.fetchTimeMillis.should.be.equal(3000);
14980
});
150-
151-
it('throws if fetchTimeMillis is not a number', function () {
152-
try {
153-
firebase.remoteConfig().setConfigSettings({ fetchTimeMillis: 'potato' });
154-
155-
return Promise.reject(new Error('Did not throw'));
156-
} catch (error) {
157-
error.message.should.containEql('must be a number type in milliseconds.');
158-
return Promise.resolve();
159-
}
160-
});
16181
});
16282

16383
describe('ensureInitialized()', function () {
@@ -201,16 +121,6 @@ describe('remoteConfig()', function () {
201121
values.some_key_1.getSource().should.equal('default');
202122
values.some_key_2.getSource().should.equal('default');
203123
});
204-
205-
it('it throws if defaults object not provided', function () {
206-
try {
207-
firebase.remoteConfig().setDefaults('not an object');
208-
return Promise.reject(new Error('Did not throw'));
209-
} catch (error) {
210-
error.message.should.containEql('must be an object.');
211-
return Promise.resolve();
212-
}
213-
});
214124
});
215125

216126
describe('getValue()', function () {
@@ -376,16 +286,6 @@ describe('remoteConfig()', function () {
376286
error.code.should.equal('remoteConfig/resource_not_found');
377287
error.message.should.containEql('was not found');
378288
});
379-
380-
it('throws if resourceName is not a string', function () {
381-
try {
382-
firebase.remoteConfig().setDefaultsFromResource(1337);
383-
return Promise.reject(new Error('Did not throw'));
384-
} catch (error) {
385-
error.message.should.containEql('must be a string value');
386-
return Promise.resolve();
387-
}
388-
});
389289
});
390290

391291
describe('reset()', function () {

0 commit comments

Comments
 (0)