51Degrees / device-detection-node

Device detection engines for Node.js implementation of the 51Degrees Pipeline API
Other
2 stars 4 forks source link

engine not started when updateOnStart:true, but dataFile is up to date #178

Closed justadreamer closed 2 months ago

justadreamer commented 3 months ago

Background

This effect occurs due to this check in deviceDetectionOnPremise.js:

    if (!updateOnStart) {
      // Not updating on start. Initialise the engine straight away

      this.initEngine();
    }

It starts the engine if updateOnStart is not needed, otherwise it expects that the updateOnStart will complete and then the engine will be started in the refresh function:

      if (current.engine) {
        return current.engine.refreshData();
      } else {
        current.initEngine().then(function () {
          current.engine.refreshData();
        });
      }

However in the case that data file update was not needed or the download was not successful - the engine will never start... The current workaround is to set updateOnStart: false in case the provided data file is up to date.

Objective

Guarantee that engine always starts independently of the value of updateOnStart flag. The engine should start with updateOnStart happening after it has started.

Test

First need to simulate / mock the scenario where Update is not needed and assert that engine exists and is started - so the test fails. Then introduce the fix that would make the test green..

cc: @Tracy51D