particle-api-js 10.5.1 → 11.0.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.
@@ -108,28 +108,6 @@ describe('Agent', () => {
108
108
  const headers = agent._getAuthorizationHeader(auth);
109
109
  expect(headers).to.eql({ Authorization: bearer });
110
110
  });
111
-
112
- if (typeof window !== 'undefined') {
113
- it('supports auth with user/pass in browsers', () => {
114
- const auth = {
115
- username: 'test@particle.io',
116
- password: 'super_secret'
117
- };
118
- const basic = 'Basic dGVzdEBwYXJ0aWNsZS5pbzpzdXBlcl9zZWNyZXQ=';
119
- const headers = agent._getAuthorizationHeader(auth);
120
- expect(headers).to.eql({ Authorization: basic });
121
- });
122
- } else {
123
- it('supports auth with user/pass in node', () => {
124
- const auth = {
125
- username: 'test@particle.io',
126
- password: 'super_secret'
127
- };
128
- const basic = 'Basic dGVzdEBwYXJ0aWNsZS5pbzpzdXBlcl9zZWNyZXQ=';
129
- const headers = agent._getAuthorizationHeader(auth);
130
- expect(headers).to.eql({ Authorization: basic });
131
- });
132
- }
133
111
  });
134
112
 
135
113
  describe('request', () => {
@@ -49,7 +49,10 @@ describe('EventStream', () => {
49
49
  expect(http.request).to.have.been.calledWith({
50
50
  hostname: 'hostname',
51
51
  protocol: 'http:',
52
- path: '/path?access_token=token',
52
+ path: '/path',
53
+ headers: {
54
+ 'Authorization': 'Bearer token'
55
+ },
53
56
  method: 'get',
54
57
  port: 8080,
55
58
  mode: 'prefer-streaming'
@@ -389,21 +389,6 @@ describe('ParticleAPI', () => {
389
389
  });
390
390
  });
391
391
 
392
- describe('.deleteAccessToken', () => {
393
- it('sends request', () => {
394
- return api.deleteAccessToken(props).then((results) => {
395
- results.should.match({
396
- method: 'delete',
397
- uri: `/v1/access_tokens/${props.token}`,
398
- auth: {
399
- username: props.username,
400
- password: props.password
401
- }
402
- });
403
- });
404
- });
405
- });
406
-
407
392
  describe('.deleteCurrentAccessToken', () => {
408
393
  it('sends request', () => {
409
394
  return api.deleteCurrentAccessToken(props).then((results) => {
@@ -428,41 +413,6 @@ describe('ParticleAPI', () => {
428
413
  });
429
414
  });
430
415
 
431
- describe('.listAccessTokens', () => {
432
- let options;
433
-
434
- beforeEach(() => {
435
- options = {
436
- username: props.username,
437
- password: props.password,
438
- otp: props.otp
439
- };
440
- });
441
-
442
- it('sends credentials', () => {
443
- delete options.otp;
444
- return api.listAccessTokens(options)
445
- .then(({ auth, query }) => {
446
- expect(auth).to.be.an('object');
447
- expect(auth).to.have.property('username', options.username);
448
- expect(auth).to.have.property('password', options.password);
449
- expect(query).to.equal(undefined);
450
- });
451
- });
452
-
453
- it('includes otp when provided', () => {
454
- return api.listAccessTokens(options)
455
- .then(({ auth, query }) => {
456
- expect(auth).to.be.an('object');
457
- expect(auth).to.have.property('username', options.username);
458
- expect(auth).to.have.property('password', options.password);
459
- expect(query).to.be.an('object');
460
- expect(query).to.have.property('otp', props.otp);
461
- expect(props.otp).to.be.a('string').with.lengthOf(6);
462
- });
463
- });
464
- });
465
-
466
416
  describe('.listDevices', () => {
467
417
  describe('user scope', () => {
468
418
  it('generates request', () => {
@@ -2889,6 +2839,77 @@ describe('ParticleAPI', () => {
2889
2839
  });
2890
2840
  });
2891
2841
 
2842
+ describe('.listDeviceOsVersions', () => {
2843
+ it('generates request without optional parameters', () => {
2844
+ return api.listDeviceOsVersions({ auth: props.auth }).then((results) => {
2845
+ results.should.match({
2846
+ method: 'get',
2847
+ uri: '/v1/device-os/versions',
2848
+ auth: props.auth,
2849
+ query: {}
2850
+ });
2851
+ });
2852
+ });
2853
+
2854
+ it('generates request with all optional parameters', () => {
2855
+ const options = {
2856
+ auth: props.auth,
2857
+ platformId: 6,
2858
+ internalVersion: '1.2.3',
2859
+ page: 2,
2860
+ perPage: 25
2861
+ };
2862
+ return api.listDeviceOsVersions(options).then((results) => {
2863
+ results.should.match({
2864
+ method: 'get',
2865
+ uri: '/v1/device-os/versions',
2866
+ auth: props.auth,
2867
+ query: {
2868
+ platform_id: 6,
2869
+ internal_version: '1.2.3',
2870
+ page: 2,
2871
+ per_page: 25
2872
+ }
2873
+ });
2874
+ });
2875
+ });
2876
+ });
2877
+
2878
+ describe('.getDeviceOsVersion', () => {
2879
+ it('generates request without optional parameters', () => {
2880
+ const options = {
2881
+ auth: props.auth,
2882
+ version: '1.2.3'
2883
+ };
2884
+ return api.getDeviceOsVersion(options).then((results) => {
2885
+ results.should.match({
2886
+ method: 'get',
2887
+ uri: '/v1/device-os/versions/1.2.3',
2888
+ auth: props.auth,
2889
+ query: {}
2890
+ });
2891
+ });
2892
+ });
2893
+
2894
+ it('generates request with platformId parameter', () => {
2895
+ const options = {
2896
+ auth: props.auth,
2897
+ version: '1.2.3',
2898
+ platformId: 6
2899
+ };
2900
+ return api.getDeviceOsVersion(options).then((results) => {
2901
+ results.should.match({
2902
+ method: 'get',
2903
+ uri: '/v1/device-os/versions/1.2.3',
2904
+ auth: props.auth,
2905
+ query: {
2906
+ platform_id: 6
2907
+ }
2908
+ });
2909
+ });
2910
+ });
2911
+ });
2912
+
2892
2913
  describe('.unprotectDevice', () => {
2893
2914
  it('generates request', () => {
2894
2915
  return api.unprotectDevice(Object.assign({}, propsWithProduct, {
@@ -2916,12 +2937,6 @@ describe('ParticleAPI', () => {
2916
2937
  });
2917
2938
  });
2918
2939
 
2919
- describe('backwards-compatibility function aliases', () => {
2920
- it('maps removeAccessToken to deleteAccessToken', () => {
2921
- api.removeAccessToken.should.equal(api.deleteAccessToken);
2922
- });
2923
- });
2924
-
2925
2940
  describe('.deviceUri', () => {
2926
2941
  describe('user scope', () => {
2927
2942
  it('gets the user device uri', () => {
@@ -3140,7 +3155,7 @@ describe('ParticleAPI', () => {
3140
3155
  error = e;
3141
3156
  }
3142
3157
  expect(error).to.be.an.instanceOf(Error);
3143
- expect(error.message).to.eql('Must pass a non-empty string or object with username and password for basic auth!');
3158
+ expect(error.message).to.eql('Must pass a non-empty string representing an auth token!');
3144
3159
  });
3145
3160
  });
3146
3161