packages/enos-sdk-samples/src/tests/subsuite_factory/connection_factory.js
/**
 * Used to create test suite for establishing a connection
 *
 * @param {DeviceClient} client
 */
Used to create test suite for establishing a connection
@param {DeviceClient} client
Used to create test suite for establishing a connection @param { DeviceClient } client
function connectionOpenSuiteFactory(client) {
  describe('Client open connection', () => {
    it('should throw an exception if brokerUrl is not provided', () => {
      expect(() => new DeviceClient({
        secureMode: SECURE_MODE.VIA_DEVICE_SECRET
      })).toThrow();
    });
    it('should throw an exception if secureMode is not provided', () => {
      expect(() => new DeviceClient({
        brokerUrl: testData.tcpBrokerUrl
      })).toThrow();
    });
    it('should throw an exception if secureMode is invalid', () => {
      expect(() => new DeviceClient({
        brokerUrl: testData.tcpBrokerUrl,
        secureMode: 0
      })).toThrow();
    });
    it('should throw an expection if secureMode is 2 and pk/dk/ds is not complete', () => {
      expect(() => new DeviceClient({
        brokerUrl: testData.tcpBrokerUrl,
        secureMode: SECURE_MODE.VIA_DEVICE_SECRET,
        productKey: 'randomKey',
        deviceKey: 'randonKey'
      })).toThrow();
    });
    it('should throw an expection if secureMode is 3 and pk/dk/ps is not complete', () => {
      expect(() => new DeviceClient({
        brokerUrl: testData.tcpBrokerUrl,
        secureMode: SECURE_MODE.VIA_DEVICE_SECRET,
        productKey: 'randomKey',
        deviceKey: 'randonKey'
      })).toThrow();
    });
    it('should throw an exception if the provided options are not valid', () => {
      const deviceClient = new DeviceClient({
        brokerUrl: testData.tcpBrokerUrl,
        secureMode: SECURE_MODE.VIA_DEVICE_SECRET,
        productKey: 'randomKey',
        deviceKey: 'randonKey',
        deviceSecret: 'randomSecret',
        mqttOptions: {
          reconnectPeriod: 0
        }
      });
      return expect(deviceClient.connect()).rejects.toThrow();
    });
    it('should connect successfully and return deviceSecret', async(done) => {
      client.on('connect', () => {
        expect(client.connected).toBe(true);
        done();
      });
      expect(client.connected).toBe(false);
      const deviceSecret = await client.connect();
      expect(client.connected).toBe(true);
      expect(deviceSecret).toEqual(client.deviceInfo.deviceSecret);
    });
  });
}
function connectionOpenSuiteFactory ( client ) { describe ( 'Client open connection' , ( ) => { it ( 'should throw an exception if brokerUrl is not provided' , ( ) => { expect ( ( ) => new DeviceClient ( { secureMode : SECURE_MODE . VIA_DEVICE_SECRET } ) ) . toThrow ( ) ; } ) ; it ( 'should throw an exception if secureMode is not provided' , ( ) => { expect ( ( ) => new DeviceClient ( { brokerUrl : testData . tcpBrokerUrl } ) ) . toThrow ( ) ; } ) ; it ( 'should throw an exception if secureMode is invalid' , ( ) => { expect ( ( ) => new DeviceClient ( { brokerUrl : testData . tcpBrokerUrl , secureMode : 0 } ) ) . toThrow ( ) ; } ) ; it ( 'should throw an expection if secureMode is 2 and pk/dk/ds is not complete' , ( ) => { expect ( ( ) => new DeviceClient ( { brokerUrl : testData . tcpBrokerUrl , secureMode : SECURE_MODE . VIA_DEVICE_SECRET , productKey : 'randomKey' , deviceKey : 'randonKey' } ) ) . toThrow ( ) ; } ) ; it ( 'should throw an expection if secureMode is 3 and pk/dk/ps is not complete' , ( ) => { expect ( ( ) => new DeviceClient ( { brokerUrl : testData . tcpBrokerUrl , secureMode : SECURE_MODE . VIA_DEVICE_SECRET , productKey : 'randomKey' , deviceKey : 'randonKey' } ) ) . toThrow ( ) ; } ) ; it ( 'should throw an exception if the provided options are not valid' , ( ) => { const deviceClient = new DeviceClient ( { brokerUrl : testData . tcpBrokerUrl , secureMode : SECURE_MODE . VIA_DEVICE_SECRET , productKey : 'randomKey' , deviceKey : 'randonKey' , deviceSecret : 'randomSecret' , mqttOptions : { reconnectPeriod : 0 } } ) ; return expect ( deviceClient . connect ( ) ) . rejects . toThrow ( ) ; } ) ; it ( 'should connect successfully and return deviceSecret' , async ( done ) => { client . on ( 'connect' , ( ) => { expect ( client . connected ) . toBe ( true ) ; done ( ) ; } ) ; expect ( client . connected ) . toBe ( false ) ; const deviceSecret = await client . connect ( ) ; expect ( client . connected ) . toBe ( true ) ; expect ( deviceSecret ) . toEqual ( client . deviceInfo . deviceSecret ) ; } ) ; } ) ; }
Used to create test suite for establishing a connection
 @param {DeviceClient} client
Used to create test suite for establishing a connection @param { DeviceClient } client