Specific Tests - Integration
  • 05 Dec 2022
  • Dark
    Light
  • PDF

Specific Tests - Integration

  • Dark
    Light
  • PDF

Article summary

The Adapter Builder will create an integration test for every API method created in the adapter.js file. The following tests are specific to the adapter and can be customized as needed to enhance/ extend testing.

NO MOCK DATA PROVIDED
If there is no mock data, the stub test will test for an error.

The integration test provides the ability to save mock data when running integrated.

runCommonAsserts: This is a private function that tests some basic aspects of a valid response.

runErrorAsserts: This is a private function that tests some basic aspects of a valid error response.

Example: No Mock Data Provided

describe('#createTenant', () => {
  it('should work if integrated but since no mockdata should error when run standalone', (done) => {
    try {
      a.createTenant(tenantName, null, (data, error) => {
        try {
          if (stub) {
            const displayE = 'Error 400 received on request’;
            runErrorAsserts(data, error, 'AD.500', 'test-apic-connectorRest-handleEndResponse', displayE);
          } else {
            runCommonAsserts(data, error);
          }
          saveMockData('poc-apic', 'createTenant', 'default', data);
          done();
        } catch (err) {
          log.error(`Test Failure: ${err}`);
          done(err);
        }
      });
    } catch (error) {
      log.error(`Adapter Exception: ${error}`);
      done(error);
    }
  }).timeout(attemptTimeout);
});

MOCK DATA PROVIDED
When mock data has been provided, the stub test will test for the data that is in the mock data file.

Example: Mock Data Approved

describe('#createTenant', () => {
  it('should work if integrated but since no mockdata should error when run standalone', (done) => {
    try {
      a.createTenant(tenantName, null, (data, error) => {
        try {
          if (stub) {
            runCommonAsserts(data, error);              
            assert.equal('string', data.response.description);
            assert.equal('string', data.response.ImportTaskId);
            assert.equal('object', typeof data.response.SnapshotTaskDetail);
          } else {
            runCommonAsserts(data, error);
          }
          saveMockData('poc-apic', 'createTenant', 'default', data);
          done();
        } catch (err) {
          log.error(`Test Failure: ${err}`);
          done(err);
        }
      });
    } catch (error) {
      log.error(`Adapter Exception: ${error}`);
      done(error);
    }
  }).timeout(attemptTimeout);
});

Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.