|
|
|
@ -1,11 +1,14 @@ |
|
|
|
|
/* eslint-disable @typescript-eslint/camelcase */ |
|
|
|
|
/* eslint-env mocha */ |
|
|
|
|
import { Meteor } from 'meteor/meteor'; |
|
|
|
|
import { expect } from 'chai'; |
|
|
|
|
import chai, { expect } from 'chai'; |
|
|
|
|
import spies from 'chai-spies'; |
|
|
|
|
|
|
|
|
|
import { Settings } from './settings.mocks'; |
|
|
|
|
import { settings } from './settings'; |
|
|
|
|
|
|
|
|
|
chai.use(spies); |
|
|
|
|
|
|
|
|
|
describe('Settings', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
Settings.upsertCalls = 0; |
|
|
|
@ -254,20 +257,21 @@ describe('Settings', () => { |
|
|
|
|
expect(Settings.upsertCalls).to.be.equal(2); |
|
|
|
|
expect(Settings.findOne({ _id: 'my_setting' })).to.include(expectedSetting); |
|
|
|
|
|
|
|
|
|
settings.addGroup('group', function() { |
|
|
|
|
this.section('section', function() { |
|
|
|
|
this.add('my_setting', 1, { |
|
|
|
|
type: 'int', |
|
|
|
|
sorter: 0, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
expectedSetting.packageValue = 1; |
|
|
|
|
|
|
|
|
|
expect(Settings.data.size).to.be.equal(2); |
|
|
|
|
expect(Settings.upsertCalls).to.be.equal(3); |
|
|
|
|
expect(Settings.findOne({ _id: 'my_setting' })).to.include(expectedSetting); |
|
|
|
|
// Can't reset setting because the Meteor.setting will have the first value and will act to enforce his value
|
|
|
|
|
// settings.addGroup('group', function() {
|
|
|
|
|
// this.section('section', function() {
|
|
|
|
|
// this.add('my_setting', 1, {
|
|
|
|
|
// type: 'int',
|
|
|
|
|
// sorter: 0,
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// expectedSetting.packageValue = 1;
|
|
|
|
|
|
|
|
|
|
// expect(Settings.data.size).to.be.equal(2);
|
|
|
|
|
// expect(Settings.upsertCalls).to.be.equal(3);
|
|
|
|
|
// expect(Settings.findOne({ _id: 'my_setting' })).to.include(expectedSetting);
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should change group and section', () => { |
|
|
|
@ -316,4 +320,41 @@ describe('Settings', () => { |
|
|
|
|
expect(Settings.upsertCalls).to.be.equal(4); |
|
|
|
|
expect(Settings.findOne({ _id: 'my_setting' })).to.include(expectedSetting); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should call `settings.get` callback on setting added', () => { |
|
|
|
|
settings.addGroup('group', function() { |
|
|
|
|
this.section('section', function() { |
|
|
|
|
this.add('setting_callback', 'value1', { |
|
|
|
|
type: 'string', |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const spy = chai.spy(); |
|
|
|
|
settings.get('setting_callback', spy); |
|
|
|
|
settings.get(/setting_callback/, spy); |
|
|
|
|
|
|
|
|
|
expect(spy).to.have.been.called.exactly(2); |
|
|
|
|
expect(spy).to.have.been.called.always.with('setting_callback', 'value1'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should call `settings.get` callback on setting changed', () => { |
|
|
|
|
const spy = chai.spy(); |
|
|
|
|
settings.get('setting_callback', spy); |
|
|
|
|
settings.get(/setting_callback/, spy); |
|
|
|
|
|
|
|
|
|
settings.addGroup('group', function() { |
|
|
|
|
this.section('section', function() { |
|
|
|
|
this.add('setting_callback', 'value2', { |
|
|
|
|
type: 'string', |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
settings.updateById('setting_callback', 'value3'); |
|
|
|
|
|
|
|
|
|
expect(spy).to.have.been.called.exactly(4); |
|
|
|
|
expect(spy).to.have.been.called.with('setting_callback', 'value2'); |
|
|
|
|
expect(spy).to.have.been.called.with('setting_callback', 'value3'); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|