jordimontana82 / fake-xrm-easy-js

FakeXrmEasy on Client Side, to unit test Web API calls from Typescript/JS. If you want to unit test plugins, code activities, or any .NET code connected to Dynamics CRM/365, check http://dynamicsvalue.com/get-started/overview
MIT License
32 stars 12 forks source link

Guid values in $filter are treated as properties instead of literal values #7

Open jordimontana82 opened 5 years ago

jordimontana82 commented 5 years ago

When filtering by Guid, literal.value is undefined, since is not interpreted as a literal value by the odata parser

Ex: emails?$select=*&$filter=_regardingobjectid_value eq 2289062e-d689-2292-51d0-d85ce235a927

Entity.prototype.satisfiesFilterEq = function (filter) {
    var property = this.getFilterProperty(filter);
    var literal = this.getFilterLiteral(filter);
    return this.attributes[property.name] === literal.value;
};
jordimontana82 commented 4 years ago

Sample unit test to reproduce:

test("$filter: eq test with Guid", done => {
    context.initialize([
        new Entity("email", Guid.create(), {description: 'Email Text 1', _regardingobjectid_value: "2289062e-d689-2292-51d0-d85ce235a927", other: "somevalue"}),
        new Entity("email", Guid.create(), {description: 'Email Text 2', _regardingobjectid_value: "2289062e-d689-2292-51d0-d85ce235a927", other: "someothervalue"})
    ]);

    WebApiClient.retrieveMultiple("emails?$filter=_regardingobjectid_value eq 2289062e-d689-2292-51d0-d85ce235a927", function (data) {

        expect(data.value.length).toBe(2); 
        expect(data.value[0].description).toBe("Email Text 1");
        expect(data.value[1].description).toBe("Email Text 2");
        done();
    });
});