2019-09-09 10:48:09 -07:00
|
|
|
const logger = require('./stub/logger');
|
2019-02-24 07:49:41 -07:00
|
|
|
const data = require('../lib/util/data.js');
|
2018-08-15 13:19:54 -07:00
|
|
|
const path = require('path');
|
2019-09-09 10:48:09 -07:00
|
|
|
const tmp = require('tmp');
|
|
|
|
const fs = require('fs');
|
2018-08-15 13:19:54 -07:00
|
|
|
|
|
|
|
describe('Data', () => {
|
|
|
|
describe('Get path', () => {
|
|
|
|
it('Should return correct path', () => {
|
|
|
|
const expected = path.normalize(path.join(__dirname, '..', 'data'));
|
2019-02-24 07:49:41 -07:00
|
|
|
const actual = data.getPath();
|
2019-03-09 14:12:10 -07:00
|
|
|
expect(actual).toBe(expected);
|
2018-08-15 13:19:54 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should return correct path when ZIGBEE2MQTT_DATA set', () => {
|
2019-09-09 10:48:09 -07:00
|
|
|
const expected = tmp.dirSync().name;
|
2018-08-15 13:19:54 -07:00
|
|
|
process.env.ZIGBEE2MQTT_DATA = expected;
|
2019-02-24 07:49:41 -07:00
|
|
|
data._reload();
|
|
|
|
const actual = data.getPath();
|
2019-03-09 14:12:10 -07:00
|
|
|
expect(actual).toBe(expected);
|
2019-09-09 10:48:09 -07:00
|
|
|
expect(data.joinPath('test')).toStrictEqual(path.join(expected, 'test'));
|
2019-02-24 07:49:41 -07:00
|
|
|
delete process.env.ZIGBEE2MQTT_DATA;
|
|
|
|
data._reload();
|
2018-08-15 13:19:54 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|