qb-admin-fe/test/modules/normalizers/checkPartialUpdate.test.js

49 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-01-08 08:29:59 +00:00
import { checkPartialUpdate } from '@/store/modules/normalizers'
import _ from 'lodash'
describe('Partial update', () => {
it('partial update for settings that do not allow partial update', () => {
const settings = { ':auto_linker': { ':opts':
{ ':strip_prefix': true, ':new_window': false, ':rel': 'ugc', ':truncate': 3 }
2020-01-08 08:29:59 +00:00
}}
const updatedSettings = { ':auto_linker': { ':opts': { ':new_window': false }}}
const description = [{
children: [
{ key: ':strip_prefix', type: 'boolean' },
{ key: ':truncate', type: ['integer', false] },
{ key: ':new_window', type: 'boolean' }],
description: 'Configuration for the auto_linker library',
group: ':auto_linker',
key: ':opts',
label: 'Opts',
type: 'group'
2020-01-08 08:29:59 +00:00
}]
const expectedData = { ':auto_linker': { ':opts': {
':strip_prefix': ['boolean', true],
':new_window': ['boolean', false],
':rel': ['', 'ugc'],
':truncate': [['integer', false], 3]
2020-01-08 08:29:59 +00:00
}}}
const updatedData = checkPartialUpdate(settings, updatedSettings, description)
expect(_.isEqual(updatedData, expectedData)).toBeTruthy()
})
it('partial update for settings that allow partial update', () => {
const settings = { ':pleroma': { 'Pleroma.Captcha': { ':enabled': true, ':seconds_valid': 70, ':method': 'Pleroma.Captcha.Kocaptcha' }}}
const updatedSettings = { ':pleroma': { 'Pleroma.Captcha': { ':seconds_valid': ['integer', 70] }}}
2020-01-08 08:29:59 +00:00
const description = [{
children: [],
description: 'Captcha-related settings',
group: ':pleroma',
key: 'Pleroma.Captcha',
label: 'Pleroma.Captcha',
type: 'group'
2020-01-08 08:29:59 +00:00
}]
const expectedData = { ':pleroma': { 'Pleroma.Captcha': { ':seconds_valid': ['integer', 70] }}}
2020-01-08 08:29:59 +00:00
const updatedData = checkPartialUpdate(settings, updatedSettings, description)
expect(_.isEqual(updatedData, expectedData)).toBeTruthy()
})
})