$kind: http-request
description: Get list of all economic activities
url: "{{csmisUrl}}/cooperative/products"
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", function () {
        const responseData = pm.response.json();

        pm.expect(responseData).to.be.an('object');
        pm.expect(responseData).to.have.property('statusCode');
        pm.expect(responseData).to.have.property('data');
        pm.expect(responseData).to.have.property('message');
      });



      pm.test("Validate the data object", function () {
          const responseData = pm.response.json();
          
          pm.expect(responseData).to.be.an('object');
          pm.expect(responseData.data).to.exist.and.to.be.an('array');
          responseData.data.forEach(function(item) {
              pm.expect(item).to.be.an('object');
              pm.expect(item.uid).to.be.null;
              pm.expect(item.name).to.be.a('string');
              pm.expect(item.grades).to.be.an('array');
          });
      });



      pm.test("Name is a non-empty string", function () {
        const responseData = pm.response.json();
        
        pm.expect(responseData).to.be.an('object');
        pm.expect(responseData.name).to.be.a('string').and.to.have.lengthOf.at.least(1, "Name should not be empty");
      });



      pm.test("Grades is an array and is not 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(product) {
              pm.expect(product.grades).to.be.an('array').and.to.have.lengthOf.at.least(1, "Grades should not be empty");
          });
      });
    language: text/javascript
order: 2000
