particle-commands 0.2.12 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +68 -0
- package/.eslintrc +1 -2
- package/.nvmrc +1 -0
- package/CHANGELOG.md +11 -0
- package/README.md +93 -1
- package/dist/cmd/library_add.js +1 -14
- package/dist/cmd/library_contribute.js +0 -10
- package/dist/cmd/library_install.js +11 -26
- package/dist/cmd/library_migrate.js +3 -4
- package/dist/cmd/library_properties.js +3 -4
- package/dist/cmd/library_publish.js +0 -8
- package/dist/cmd/project_init.js +0 -3
- package/dist/cmd/project_properties.js +9 -12
- package/dist/cmd/templates/project/README.md +2 -2
- package/dist/index.js +9 -28
- package/package.json +20 -20
- package/src/cmd/library_add.js +2 -8
- package/src/cmd/library_contribute.js +0 -3
- package/src/cmd/library_install.js +7 -16
- package/src/cmd/library_publish.js +0 -3
- package/src/cmd/project_init.js +1 -3
- package/src/cmd/templates/project/README.md +2 -2
- package/src/index.js +0 -8
- package/test/cmd/library_install.spec.js +1 -1
- package/test/cmd/library_list.spec.js +5 -9
- package/test/cmd/library_publish.spec.js +1 -1
- package/test/cmd/project_init.spec.js +1 -4
- package/test/cmd/projects_spec.js +4 -4
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/misc.xml +0 -13
- package/.idea/modules.xml +0 -8
- package/.idea/particle-commands.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -222
- package/.npmignore +0 -1
- package/.travis.yml +0 -2
- package/dist/lib/analytics.js +0 -229
- package/dist/lib/settings.js +0 -410
- package/dist/lib/utilities.js +0 -27
- package/src/lib/analytics.js +0 -182
- package/src/lib/settings.js +0 -359
- package/src/lib/utilities.js +0 -24
- package/test/lib/analytics.spec.js +0 -158
- package/test/lib/settings.spec.js +0 -27
- package/yarn.lock +0 -4690
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { expect, sinon } from '../test-setup';
|
|
2
|
-
|
|
3
|
-
import { track, flush, test } from '../../src/lib/analytics';
|
|
4
|
-
const CommandContext = test.CommandContext;
|
|
5
|
-
|
|
6
|
-
const SegmentKey = 'DFhKeLxnEmFVs3ejUDFUj5UH4Vv7SvUO';
|
|
7
|
-
|
|
8
|
-
describe('analytics', () => {
|
|
9
|
-
const tool = { name: 'cli', version: '1.2.3' };
|
|
10
|
-
const api = { key: 'apikey' };
|
|
11
|
-
const auth = 'blahblah';
|
|
12
|
-
|
|
13
|
-
describe('context object', () => {
|
|
14
|
-
function commandContext() {
|
|
15
|
-
const sut = new CommandContext();
|
|
16
|
-
sut.trackingUser = () => Promise.resolve({ id:'abcd', email:'someone@example.com' });
|
|
17
|
-
return sut.buildContext({tool, api, auth});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
it('has user.id', () => {
|
|
21
|
-
return expect(commandContext()).to.eventually.have.property('user').to.have.property('id').eql('abcd');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('has user.email', () => {
|
|
25
|
-
return expect(commandContext()).to.eventually.have.property('user').to.have.property('email').eql('someone@example.com');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('has api.key', () => {
|
|
29
|
-
return expect(commandContext()).to.eventually.have.property('api').to.have.property('key').to.be.ok;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('has tool.name', () => {
|
|
33
|
-
return expect(commandContext()).to.eventually.have.property('tool').to.have.property('name').to.eql('cli');
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('identifyUser', () => {
|
|
38
|
-
it('rejects when api is not ready', () => {
|
|
39
|
-
const sut = new CommandContext();
|
|
40
|
-
const api = { ready: sinon.stub().returns(false) };
|
|
41
|
-
return expect(sut.identifyUser(api)).to.eventually.be.rejected;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('resolves with the user when ready', () => {
|
|
45
|
-
const sut = new CommandContext();
|
|
46
|
-
const user = { id:'123' };
|
|
47
|
-
const api = { ready: sinon.stub().returns(true), trackingIdentity: sinon.stub().resolves(user) };
|
|
48
|
-
return expect(sut.identifyUser(api)).to.eventually.eql(user);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('isIdentity', () => {
|
|
53
|
-
const isIdentity = new CommandContext().isIdentity;
|
|
54
|
-
|
|
55
|
-
it('returns true when id and email are present', () => {
|
|
56
|
-
expect(isIdentity({ id:'123', email:'email' })).to.be.true;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('returns false if any property is missing', () => {
|
|
60
|
-
expect(isIdentity({ id:'123' })).to.be.false;
|
|
61
|
-
expect(isIdentity({ email:'123' })).to.be.false;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('returns false for a null reference', () => {
|
|
65
|
-
expect(isIdentity(null)).to.be.false;
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('trackUser', () => {
|
|
70
|
-
const user = { id: '123', email: 'biffa@viz.co.uk' };
|
|
71
|
-
|
|
72
|
-
it('resolves the existing identity when already present in settings', () => {
|
|
73
|
-
const sut = new CommandContext();
|
|
74
|
-
sut.identifyUser = sinon.stub().throws(new Error('do not touch'));
|
|
75
|
-
const identity = sinon.stub().returns(user);
|
|
76
|
-
expect(sut.trackingUser(identity)).to.eventually.eql(user);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('calls identifyUser when not already present in settings and saves it to settings', () => {
|
|
80
|
-
const sut = new CommandContext();
|
|
81
|
-
const identity = sinon.stub();
|
|
82
|
-
const client = { trackingIdentity: sinon.stub().returns(Promise.resolve(user))};
|
|
83
|
-
const clientFactory = sinon.stub().returns(client);
|
|
84
|
-
sut.identifyUser = sinon.stub().resolves(user);
|
|
85
|
-
const auth = 'xyz';
|
|
86
|
-
return sut.trackingUser(identity, auth, clientFactory)
|
|
87
|
-
.then(user_ => {
|
|
88
|
-
expect(user_).to.be.eql(user);
|
|
89
|
-
expect(identity).calledWith(user);
|
|
90
|
-
expect(clientFactory).calledWith(auth);
|
|
91
|
-
expect(client.trackingIdentity).not.called; // because we stub identifyUser where it is called from
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('calls identifyUser when not already present, and returns null if the fetched user fails the identify call', () => {
|
|
96
|
-
const sut = new CommandContext();
|
|
97
|
-
const cache = sinon.stub();
|
|
98
|
-
const auth = 'xyz';
|
|
99
|
-
const client = 'client';
|
|
100
|
-
const clientFactory = sinon.stub().returns(client);
|
|
101
|
-
sut.identifyUser = sinon.stub().resolves(user);
|
|
102
|
-
sut.isIdentity = sinon.stub().returns(false);
|
|
103
|
-
return sut.trackingUser(cache, auth, clientFactory)
|
|
104
|
-
.then(user_ => {
|
|
105
|
-
expect(user_).to.be.eql(null);
|
|
106
|
-
expect(sut.identifyUser).calledWith(client);
|
|
107
|
-
expect(cache.withArgs(sinon.match.any)).to.not.be.called;
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('track', () => {
|
|
113
|
-
const command = {};
|
|
114
|
-
const site = {};
|
|
115
|
-
|
|
116
|
-
it('implements flush', () => {
|
|
117
|
-
const promise = flush();
|
|
118
|
-
expect(promise).to.eventually.be.ok;
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('can track an event against a user id', () => {
|
|
122
|
-
const userId = 'test-no-indentify';
|
|
123
|
-
const command = {};
|
|
124
|
-
const site = {};
|
|
125
|
-
const context = {
|
|
126
|
-
tool: { name: 'particle-commands unit tests' },
|
|
127
|
-
api: { key: SegmentKey },
|
|
128
|
-
user: { id: userId }
|
|
129
|
-
};
|
|
130
|
-
const event = 'integration-test';
|
|
131
|
-
const properties = { foo:'bar' };
|
|
132
|
-
|
|
133
|
-
const promise = track({ command, context, site, event, properties });
|
|
134
|
-
return expect(promise).to.eventually.be.ok;
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('raises an error when the api key is not provided', () => {
|
|
138
|
-
return expect(() => track({ command, context:{ user: { id:'abcd' } }, site, event:'this should not appear', traits:{ foo:'bar' } }))
|
|
139
|
-
.to.throw('context.api.key not provided');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('raises an error when the user id is not provided', () => {
|
|
143
|
-
return expect(() => track({ command, context:{ api: { key:'abcd' } }, site, event:'this should not appear', traits:{ foo:'bar' } }))
|
|
144
|
-
.to.throw('context.user.id not provided');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('returns silently when track:false is defined', () => {
|
|
148
|
-
return expect(track({ command, context:{ user: { track: false } }, site, event:'this should not appear', traits:{ foo:'bar' } }))
|
|
149
|
-
.to.eventually.resolve;
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('raises an error when track:true is defined', () => {
|
|
153
|
-
return expect(() => track({ command, context:{ user: { track: true } }, site, event:'this should not appear', traits:{ foo:'bar' } }))
|
|
154
|
-
.to.throw('context.user.id not provided');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { buildSettings } from '../../src/lib/settings';
|
|
2
|
-
import { expect } from '../test-setup';
|
|
3
|
-
|
|
4
|
-
describe('settings', () => {
|
|
5
|
-
describe('buildSettings', () => {
|
|
6
|
-
it('combines the settings with the default settings', () => {
|
|
7
|
-
const settings = buildSettings(true, { a:'b' }, true);
|
|
8
|
-
expect(settings.get('a')).to.eql('b');
|
|
9
|
-
expect(settings).to.not.have.property('a');
|
|
10
|
-
expect(settings.get('access_token')).to.be.eql(null); // is null by default
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('can apply the settings on the outer object', () => {
|
|
14
|
-
const settings = buildSettings(false, { a:'b' }, true);
|
|
15
|
-
expect(settings).to.have.property('a').eql('b');
|
|
16
|
-
expect(settings.get('a')).to.be.eql('b');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('overrides the settings from the provided settings', () => {
|
|
20
|
-
const settings = buildSettings(true, { a:'b', access_token:'abcd' }, true);
|
|
21
|
-
expect(settings.get('a')).to.eql('b');
|
|
22
|
-
expect(settings.get('access_token')).to.be.eql('abcd');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|