forked from AkkomaGang/admin-fe
Add tests for partial update
This commit is contained in:
parent
1b368c7786
commit
eabc4464df
2 changed files with 48 additions and 1 deletions
|
@ -1,7 +1,6 @@
|
||||||
export const checkPartialUpdate = (settings, updatedSettings, description) => {
|
export const checkPartialUpdate = (settings, updatedSettings, description) => {
|
||||||
return Object.keys(updatedSettings).reduce((acc, group) => {
|
return Object.keys(updatedSettings).reduce((acc, group) => {
|
||||||
acc[group] = Object.keys(updatedSettings[group]).reduce((acc, key) => {
|
acc[group] = Object.keys(updatedSettings[group]).reduce((acc, key) => {
|
||||||
debugger
|
|
||||||
if (!partialUpdate(group, key)) {
|
if (!partialUpdate(group, key)) {
|
||||||
const updated = Object.keys(settings[group][key]).reduce((acc, settingName) => {
|
const updated = Object.keys(settings[group][key]).reduce((acc, settingName) => {
|
||||||
const setting = description
|
const setting = description
|
||||||
|
|
48
test/modules/normalizers/checkPartialUpdate.test.js
Normal file
48
test/modules/normalizers/checkPartialUpdate.test.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
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 }
|
||||||
|
}}
|
||||||
|
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"
|
||||||
|
}]
|
||||||
|
|
||||||
|
const expectedData = { ':auto_linker': { ':opts': {
|
||||||
|
':strip_prefix': ["boolean", true],
|
||||||
|
':new_window': ["boolean", false],
|
||||||
|
':rel': ['', "ugc"],
|
||||||
|
':truncate': [["integer", false], 3]
|
||||||
|
}}}
|
||||||
|
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] }}}
|
||||||
|
const description = [{
|
||||||
|
children: [],
|
||||||
|
description: "Captcha-related settings",
|
||||||
|
group: ":pleroma",
|
||||||
|
key: "Pleroma.Captcha",
|
||||||
|
label: "Pleroma.Captcha",
|
||||||
|
type: "group"
|
||||||
|
}]
|
||||||
|
|
||||||
|
const expectedData = { ':pleroma': { 'Pleroma.Captcha': { ':seconds_valid': ["integer", 70] }}}
|
||||||
|
const updatedData = checkPartialUpdate(settings, updatedSettings, description)
|
||||||
|
expect(_.isEqual(updatedData, expectedData)).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue