$kind: http-request
description: |-
  Get list of all District

   **On Success**
      
      ``` Json
        { 
            "statusCode": 8000, 
            "data": [
                      {
                          "uid": "2b52bff0-726d-4de7-b5c9-4641b691e958",
                          "districtName": "Korogwe",
                          "districtCode": "TN02",
                          "regionUid": "1ec3fd53-27fd-4574-9983-4e3b115feb6e"
                      }
            ],
            "message": "Success"
        }
      
      ```
url: "{{csmisUrl}}/location/districts"
method: GET
scripts:
  - type: afterResponse
    code: >-
      pm.test("Response status code is 200", function () {
        pm.expect(pm.response.code).to.equal(200);
      });



      pm.test("Response has the required fields - statusCode, data, and
      message", function () {
          const responseData = pm.response.json();
          
          pm.expect(responseData).to.be.an('object');
          pm.expect(responseData.statusCode).to.exist;
          pm.expect(responseData.data).to.exist;
          pm.expect(responseData.message).to.exist;
      });



      pm.test("Validate the data object", function () {
          const responseData = pm.response.json();
          
          pm.expect(responseData).to.have.property('data').that.is.an('array').with.lengthOf.at.least(1);
          responseData.data.forEach(function(item) {
              pm.expect(item).to.have.property('uid').that.is.a('string');
              pm.expect(item).to.have.property('districtName').that.is.a('string');
              pm.expect(item).to.have.property('districtCode').that.is.a('string');
              pm.expect(item).to.have.property('regionUid').that.is.a('string');
          });
      });



      pm.test("Data array is present and contains the expected number of
      elements", function () {
          const responseData = pm.response.json();

          pm.expect(responseData).to.have.property('data').that.is.an('array').with.lengthOf(1);
      });



      pm.test("Verify that the 'uid,' 'districtName,' 'districtCode,' and
      'regionUid' in the 'data' array are not null or empty", function () {
          const responseData = pm.response.json();
          
          pm.expect(responseData).to.be.an('object');
          pm.expect(responseData.data).to.be.an('array');
          
          responseData.data.forEach(function(item) {
              pm.expect(item.uid).to.exist.and.to.not.be.empty;
              pm.expect(item.districtName).to.exist.and.to.not.be.empty;
              pm.expect(item.districtCode).to.exist.and.to.not.be.empty;
              pm.expect(item.regionUid).to.exist.and.to.not.be.empty;
          });
      });
    language: text/javascript
order: 2000
