BlinkUX/sequelize-mock

Declaring a Mock with a GEOMETRY Field

dalexander-trc opened this issue · 0 comments

Description of the Issue

Attempting to create a mock with a geometry field so that it can utilize geometry extensions in the tested module. The extension methods are not recognized as functions by the mock. Not sure if this is because I've declared my mocks incorrectly or because I am trying to access an extension method through a mocked object.

EDIT: Solution

The extensions in question are only enabled through Docker containers. As a result, I had to set up a Docker container to host these Mocha tests.

my-test.js

const wkx = require("../common/wkxExt");
const SequelizeMock = require('sequelize-mock');
var DBConnectionMock = new SequelizeMock();

var ShapeMock = DBConnectionMock.define('shape', {
        'name': 'testing',
        'desc': 'a line from 0,1 to 10,1',
        'geom': { type: SequelizeMock.GEOMETRY("GEOMETRYM", 4269) }
})

const proxyquire = require('proxyquire');
var MyModule = proxyquire('./my-module', {
    '../common/models': ShapeMock
});

describe('Shape Tests', function () {
    it("should run the task", function (done) {
        var shapeGeo = wkx.Geometry.parse('0102000020AD100000020000000000000000000000000000000000F03F0000000000002440000000000000F03F', 'hex');
        ShapeMock.$queueResult(ShapeMock.build({ geom: shapeGeo }));
        MyModule.onRun().then(() => {
            done();
        })
    });
});

my-module.js

const wkx = require("../common/wkxExt");

...

.then(theshape=> {
     // .toGeos() is an extension declared in wkxExt for postgres geom fields
     var shapeGeos = theshape.geom.toGeos();
})

Actual Result

TypeError: theshape.geom.toGeos is not a function, the value declared in the queueResult is visible.

Expected Result

The geom field is of type GEOMETRY and the associated extension methods are accessible.