Example #1
0
 it(`adds an auth header to hydra requests`, () => Promise.all([
   assert.becomes(interceptor.onRequest({
     uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`
   }), {
     uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`,
     headers: {
       authorization: `Bearer ST1`
     }
   }),
   assert.becomes(interceptor.onRequest({
     uri: `https://hydra-a.wbx.com/ping`
   }), {
     uri: `https://hydra-a.wbx.com/ping`,
     headers: {
       authorization: `Bearer ST1`
     }
   }),
   assert.becomes(interceptor.onRequest({
     service: `hydra`,
     resource: `ping`
   }), {
     service: `hydra`,
     resource: `ping`,
     headers: {
       authorization: `Bearer ST1`
     }
   })
 ]));
Example #2
0
      it(`retrieves avatar urls for multiple sizes for the same user`, () => {
        spark.request = sinon.stub().returns(Promise.resolve({
          body: {
            '88888888-4444-4444-4444-aaaaaaaaaaa0': {
              40: {
                size: 40,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0--40`
              }
            },
            '88888888-4444-4444-4444-aaaaaaaaaaa1': {
              40: {
                size: 40,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1--40`
              },
              110: {
                size: 110,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1--110`
              }
            }
          },
          statusCode: 200,
          options: {
            ids: [
              `88888888-4444-4444-4444-aaaaaaaaaaa0`,
              `88888888-4444-4444-4444-aaaaaaaaaaa1`
            ],
            body: [
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa0`,
                sizes: [40]
              },
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa1`,
                sizes: [40, 110]
              }
            ]
          }
        }));

        return Promise.all([
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa0`, {size: 40}), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0--40`),
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa1`, {size: 40}), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1--40`),
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa1`, {size: 110}), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1--110`)
        ])
          .then(() => {
            assert.callCount(spark.request, 1);
          });
      });
Example #3
0
      it(`retrieves an avatar url for a non-default size`, () => {
        spark.request = sinon.stub().returns(Promise.resolve({
          body: {
            '88888888-4444-4444-4444-aaaaaaaaaaa0': {
              110: {
                size: 110,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0--40`
              }
            }
          },
          statusCode: 200,
          options: {
            ids: [
              `88888888-4444-4444-4444-aaaaaaaaaaa0`
            ],
            body: [
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa0`,
                sizes: [110]
              }
            ]
          }
        }));

        return assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa0`, {size: 110}), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0--40`);
      });
Example #4
0
 it(`retrieves an avatar url`, () => {
   spark.request = sinon.stub().returns(Promise.resolve({
     body: {
       '88888888-4444-4444-4444-aaaaaaaaaaa0': {
         80: {
           size: 80,
           url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0`
         }
       }
     },
     statusCode: 200,
     options: {
       ids: [
         `88888888-4444-4444-4444-aaaaaaaaaaa0`
       ],
       body: [
         {
           uuid: `88888888-4444-4444-4444-aaaaaaaaaaa0`,
           sizes: [80]
         }
       ]
     }
   }));
   const deferred = avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa0`);
   return assert.becomes(deferred, `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0`);
 });
Example #5
0
 it(`adds an auth header to service catalog requests`, () => Promise.all([
   assert.becomes(interceptor.onRequest({
     uri: `https://service.example.com/ping`
   }), {
     uri: `https://service.example.com/ping`,
     headers: {
       authorization: `Bearer ST1`
     }
   }),
   assert.becomes(interceptor.onRequest({
     uri: `https://not-a-service.example.com/ping`
   }), {
     headers: {},
     uri: `https://not-a-service.example.com/ping`
   })
 ]));
Example #6
0
 it(`adds an auth header to hydra requests`, () => assert.becomes(interceptor.onRequest({
   uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`
 }), {
   uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`,
   headers: {
     authorization: `Bearer ST1`
   }
 }));
Example #7
0
      it(`retrieves avatar urls for homogenous, non-standard sizes`, () => {
        spark.request = sinon.stub().returns(Promise.resolve({
          body: {
            '88888888-4444-4444-4444-aaaaaaaaaaa0': {
              100: {
                size: 110,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0--110`
              }
            },
            '88888888-4444-4444-4444-aaaaaaaaaaa1': {
              100: {
                size: 110,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1--110`
              }
            }
          },
          statusCode: 200,
          options: {
            ids: [
              `88888888-4444-4444-4444-aaaaaaaaaaa0`,
              `88888888-4444-4444-4444-aaaaaaaaaaa1`
            ],
            body: [
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa0`,
                sizes: [100]
              },
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa1`,
                sizes: [100]
              }
            ]
          }
        }));

        return Promise.all([
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa0`, {size: 100}), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0--110`),
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa1`, {size: 100}), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1--110`)
        ])
          .then(() => {
            assert.callCount(spark.request, 1);
          });
      });
Example #8
0
      it(`retrieves a group of avatar urls`, () => {
        spark.request = sinon.stub().returns(Promise.resolve({
          body: {
            '88888888-4444-4444-4444-aaaaaaaaaaa0': {
              80: {
                size: 80,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0`
              }
            },
            '88888888-4444-4444-4444-aaaaaaaaaaa1': {
              80: {
                size: 80,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1`
              }
            }
          },
          statusCode: 200,
          options: {
            ids: [
              `88888888-4444-4444-4444-aaaaaaaaaaa0`,
              `88888888-4444-4444-4444-aaaaaaaaaaa1`
            ],
            body: [
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa0`,
                sizes: [80]
              },
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa1`,
                sizes: [80]
              }
            ]
          }
        }));

        return Promise.all([
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa0`), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0`),
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa1`), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa1`)
        ])
          .then(() => {
            assert.callCount(spark.request, 1);
          });
      });
Example #9
0
 it(`does not replace the auth header if one has been provided`, () => assert.becomes(interceptor.onRequest({
   uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`,
   headers: {
     authorization: `Bearer Alternate`
   }
 }), {
   uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`,
   headers: {
     authorization: `Bearer Alternate`
   }
 }));
Example #10
0
      it(`rejects each avatar missing from the response`, () => {
        spark.request = sinon.stub().returns(Promise.resolve({
          body: {
            '88888888-4444-4444-4444-aaaaaaaaaaa0': {
              80: {
                size: 80,
                url: `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0`
              }
            }
          },
          statusCode: 200,
          options: {
            ids: [
              `88888888-4444-4444-4444-aaaaaaaaaaa0`,
              `88888888-4444-4444-4444-aaaaaaaaaaa1`
            ],
            body: [
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa0`,
                sizes: [80]
              },
              {
                uuid: `88888888-4444-4444-4444-aaaaaaaaaaa1`,
                sizes: [80]
              }
            ]
          }
        }));

        return Promise.all([
          assert.becomes(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa0`), `https://example.com/88888888-4444-4444-4444-aaaaaaaaaaa0`),
          assert.isRejected(avatar.retrieveAvatarUrl(`88888888-4444-4444-4444-aaaaaaaaaaa1`), /Failed to retrieve avatar/)
        ])
          .then(() => {
            assert.callCount(spark.request, 1);
          });
      });
 it(`fingerprintResponse returns 'uuid-size'`, () => assert.becomes(batcher.fingerprintRequest({uuid: `uuid1`, size: 80}), `uuid1-80`));
Example #12
0
 it(`does not add an auth header if ${falsey} has been provided`, () => assert.becomes(interceptor.onRequest({
   uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`,
   headers: {
     authorization: falsey
   }
 }), {
   uri: `${config.device.preDiscoveryServices.hydraServiceUrl}/ping`,
   headers: {}
 }));