Skip to content

InMemoryBackendService - Model id as "0" always returns 404 from in-memory-backend-service.js #12

@CTTillman1941

Description

@CTTillman1941

[x ] bug report

I should be able to mock a fake backend service using a primary id of my model object as "0". Instead, it always returns a "404" error in that case. The cause is an "if" conditional in InMemoryBackendService.prototype.delete method. "0" evaluates as falsey which causes the method to execute "this.createErrorResponse(http_status_codes_1.STATUS.NOT_FOUND...)". It also appears that "put" and "post" have similar issues.

Existing framework code:

InMemoryBackendService.prototype.delete = function (_a) {
        var id = _a.id, collection = _a.collection, collectionName = _a.collectionName, headers = _a.headers;
        if (!id) { //<---- Right here is the issue, id "0" evaluates as "falsey"
            return this.createErrorResponse(http_status_codes_1.STATUS.NOT_FOUND, "Missing \"" + collectionName + "\" id");
        }
        var exists = this.removeById(collection, id);
        return new http_1.ResponseOptions({
            headers: headers,
            status: (exists || !this.config.delete404) ? http_status_codes_1.STATUS.NO_CONTENT : http_status_codes_1.STATUS.NOT_FOUND
        });
    };
  • Angular version: 2.0.0-rc.4
  • Browser: all
  • Language: all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions