Skip to content

Commit d28eede

Browse files
author
Sefa Ilkimen
committed
some refactoring:
- new module for messages - new module for helper functions
1 parent 25b4a28 commit d28eede

File tree

7 files changed

+282
-250
lines changed

7 files changed

+282
-250
lines changed

plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<dependency id="cordova-plugin-file" version=">=2.0.0"/>
1111
<js-module src="www/lodash.js" name="lodash"/>
1212
<js-module src="www/umd-tough-cookie.js" name="tough-cookie"/>
13+
<js-module src="www/messages.js" name="messages"/>
1314
<js-module src="www/local-storage-store.js" name="local-storage-store"/>
1415
<js-module src="www/cookie-handler.js" name="cookie-handler"/>
1516
<js-module src="www/angular-integration.js" name="angular-integration"/>
17+
<js-module src="www/helpers.js" name="helpers"/>
1618
<js-module src="www/advanced-http.js" name="http">
1719
<clobbers target="cordova.plugin.http"/>
1820
</js-module>

test/js-mocha-specs.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ const mock = require('mock-require');
33
const path = require('path');
44

55
const should = chai.should();
6+
7+
const HELPERS_ID = path.resolve(__dirname, '..', 'www', 'helpers');
68
const PLUGIN_ID = path.resolve(__dirname, '..', 'www', 'advanced-http');
79

810
describe('Advanced HTTP www interface', function() {
911
let http = {};
12+
let helpers = {};
13+
1014
const noop = () => { /* intentionally doing nothing */ };
15+
1116
const loadHttp = () => {
17+
mock(`${PLUGIN_ID}.helpers`, mock.reRequire('../www/helpers'));
1218
http = mock.reRequire('../www/advanced-http');
1319
};
1420

@@ -19,8 +25,12 @@ describe('Advanced HTTP www interface', function() {
1925
global.btoa = decoded => new Buffer(decoded).toString('base64');
2026

2127
mock('cordova/exec', noop);
22-
mock(`${PLUGIN_ID}.angular-integration`, { registerService: noop });
2328
mock(`${PLUGIN_ID}.cookie-handler`, {});
29+
mock(`${HELPERS_ID}.cookie-handler`, {});
30+
mock(`${PLUGIN_ID}.messages`, require('../www/messages'));
31+
mock(`${HELPERS_ID}.messages`, require('../www/messages'));
32+
mock(`${PLUGIN_ID}.angular-integration`, { registerService: noop });
33+
2434
loadHttp();
2535
});
2636

@@ -40,7 +50,7 @@ describe('Advanced HTTP www interface', function() {
4050
});
4151

4252
it('resolves global headers correctly #24', () => {
43-
mock(`${PLUGIN_ID}.cookie-handler`, {
53+
mock(`${HELPERS_ID}.cookie-handler`, {
4454
getCookieString: () => 'fakeCookieString'
4555
});
4656

@@ -59,7 +69,7 @@ describe('Advanced HTTP www interface', function() {
5969
});
6070

6171
it('resolves host headers correctly (set without port number) #37', () => {
62-
mock(`${PLUGIN_ID}.cookie-handler`, {
72+
mock(`${HELPERS_ID}.cookie-handler`, {
6373
getCookieString: () => 'fakeCookieString'
6474
});
6575

@@ -78,7 +88,7 @@ describe('Advanced HTTP www interface', function() {
7888
});
7989

8090
it('resolves host headers correctly (set with port number) #37', () => {
81-
mock(`${PLUGIN_ID}.cookie-handler`, {
91+
mock(`${HELPERS_ID}.cookie-handler`, {
8292
getCookieString: () => 'fakeCookieString'
8393
});
8494

@@ -97,7 +107,7 @@ describe('Advanced HTTP www interface', function() {
97107
});
98108

99109
it('resolves request headers correctly', () => {
100-
mock(`${PLUGIN_ID}.cookie-handler`, {
110+
mock(`${HELPERS_ID}.cookie-handler`, {
101111
getCookieString: () => 'fakeCookieString'
102112
});
103113

0 commit comments

Comments
 (0)