How do it test on Jasmine in 7.8

#1

Hi all. In 7.6, for tests on Jasmine, they existed the fields “content” and “contentType” in “ContentRef” type . Through these fields, test on Jasmine in 7.6 correctly worked.
Now in 7.8, in “ContentRef” type there aren’t more these 2 fields. What are the fields in “ContentRef” type that substitute “content” and “contentType” fields?

0 Likes

#2

Hi, someone can help us about this issue? We used in previous version (7.2 or 7.6) jasmine test (for canonical) that were defined as (for example:

var stringaCsv = “tag;value;timestamp;quality\n”+
“ID_0001;22,8;2018-09-01T13:00:00.205Z;true\n”+
“ID_0002;24,1;2018-09-05T01:00:00.152Z;true”;

Then for test the Canonical import data, we declared:

//construct the spec object to pass to the function
var spec = {content:{content:stringaCsv, contentType:“text/csv”}};
//call the importData to test the canonical
var result = CanonicalBMS.importData(spec);

Now this kind of tests doesn’t work because the type ContentRef has been updated. Which is the right way to update this kind of tests in order to verify Canonical import?

Thanks,
Laura

0 Likes

#3

Hey Laura. Here’s an example of a test that we use internally:

var filename = "test_TransformCanonicalEfficiencyEdContentToRelatedEnergyConservationOptionContent";
describe(filename, function () {
    beforeEach(function () {
    this.input = CanonicalEfficiencyEdContent.make({
      name: "Financial Available",
      description: "Click here to see the offer",
      contentType: "Related",
      recCode: "efficient_boiler",
      relatedEnergyConservationOption: "eco_1",
      displayCondition: undefined,
      order: 1,
      opCo: undefined
    });
  });

  var modifyBaseInput = function(fields) {
    beforeEach(function () {
      this.input = this.input.putFields(fields);
      this.output = TransformCanonicalEfficiencyEdContentToRelatedEnergyConservationOptionContent.transform(this.input);
    });
  }

  describe("content with type RelatedEnergyConservationOption", function () {
    describe("transforms id", function () {
      describe("order 1", function () {
        modifyBaseInput({order: 1});

        it("sets id", function () {
          expect(this.output.id).toBe("rec_content_efficient_boiler_related_1");
        });
      });

      describe("order omitted", function () {
        modifyBaseInput({order: null});

        it("sets id", function () {
          expect(this.output.id).toBe("rec_content_efficient_boiler_related_0");
        });
      });
    });

    describe("transforms name", function () {
      modifyBaseInput({name: "Financial Available"});

      it("sets name", function () {
        expect(this.output.name).toBe("Financial Available");
      });
    });

    describe("transforms energyConservationOption", function () {
      modifyBaseInput({recCode: "test_recommendation"});

      it("sets energyConservationOption", function () {
        expect(this.output.energyConservationOption).toBeDefined();
        expect(this.output.energyConservationOption.id).toBe("test_recommendation");
      });
    });

    describe("transforms operatingCompanies", function () {
      describe("opCo omitted", function () {
        modifyBaseInput({opCo: null});

        it("does not set operatingCompanies", function () {
          expect(this.output.operatingCompanies.size()).toBe(0);
        });
      });

      describe("opCo provided", function () {
        modifyBaseInput({opCo: "JACK, JILL"});

        it("sets operatingCompanies", function () {
          expect(this.output.operatingCompanies).toBeDefined();
          expect(this.output.operatingCompanies.size()).toBe(2);
          expect(this.output.operatingCompanies[0].id).toBe("JACK");
          expect(this.output.operatingCompanies[1].id).toBe("JILL");
        });
      });
    });

    describe("transforms displayCondition", function () {
      describe("displayCondition omitted", function () {
        modifyBaseInput({displayCondition: null});

        it("does not set applicableCondition", function () {
          expect(this.output.applicableCondition).toBeUndefined();
        });
      });

      describe("displayCondition provided", function () {
        modifyBaseInput({displayCondition: "some_field == \"some_value\""});

        it("sets applicableCondition", function () {
          expect(this.output.applicableCondition).toBe("some_field == \"some_value\"");
        });
      });
    });

    describe("transforms urlLabel", function () {
      describe("description omitted", function () {
        modifyBaseInput({description: null});

        it("does not set urlLabel", function () {
          expect(this.output.urlLabel).toBeUndefined();
        });
      });

      describe("description provided", function () {
        modifyBaseInput({description: "Up to $500 incentive on select equipment."});

        it("sets urlLabel", function () {
          expect(this.output.urlLabel).toBe("Up to $500 incentive on select equipment.");
        });
      });
    });

    describe("transforms relatedEnergyConservationOption", function () {
      describe("description omitted", function () {
        modifyBaseInput({relatedEnergyConservationOption: null});

        it("does not set relatedEnergyConservationOption", function () {
          expect(this.output.relatedEnergyConservationOption).toBeUndefined();
        });
      });

      describe("description provided", function () {
        modifyBaseInput({relatedEnergyConservationOption: 'eco_1'});

        it("does not set relatedEnergyConservationOption", function () {
          expect(this.output.relatedEnergyConservationOption.id).toBe('eco_1');
        });
      });
    });
  });
});

This isn’t exactly what you’re doing, but it could be helpful. Are you aware of the Canonical tests? There’s a way to specifically tests canonicals by providing input and expected output as csv files. Check the documentation called “Data Load Canonical Tests” which is at path: documentation/topic/canonical-tests. You could also check the type CanonicalTestRunner.

0 Likes

#4

@AlexBakic had same issue after upgrading to 7.8, you may try his quick fix CanonicalImportDataSpec content type

0 Likes

#5

Hi @rileysiebel , thanks for the reply! I will try with you suggestion and let you know :slight_smile:

0 Likes