Add tests for normal tuples, retries and tuples with objects
This commit is contained in:
parent
624d0cb76c
commit
558d3bedc8
2 changed files with 49 additions and 4 deletions
|
@ -64,9 +64,6 @@ export const parseTuples = (tuples, key) => {
|
|||
accum[item.tuple[0]] = item.tuple[1] === ':disabled' ? [item.tuple[1]] : item.tuple[1].tuple
|
||||
} else if (item.tuple[0] === ':proxy_url') {
|
||||
accum[item.tuple[0]] = parseProxyUrl(item.tuple[1])
|
||||
} else if ((item.tuple[0] === ':sslopts' && item.tuple[1].length === 0) ||
|
||||
(item.tuple[0] === ':tlsopts' && item.tuple[1].length === 0)) {
|
||||
accum[item.tuple[0]] = {}
|
||||
} else if (item.tuple[0] === ':args') {
|
||||
accum[item.tuple[0]] = parseNonTuples(item.tuple[0], item.tuple[1])
|
||||
} else if (Array.isArray(item.tuple[1]) &&
|
||||
|
|
|
@ -3,7 +3,23 @@ import _ from 'lodash'
|
|||
|
||||
describe('Parse tuples', () => {
|
||||
it('parse tuples', () => {
|
||||
//string, boolean, int, array
|
||||
const tuples = [
|
||||
{ tuple: [":enabled", false]},
|
||||
{ tuple: [":host", "localhost"]},
|
||||
{ tuple: [":port", 389]},
|
||||
{ tuple: [':tlsopts', ['test', 'test1']]},
|
||||
{ tuple: [':sslopts', [{ tuple: [":cacertfile", "path/to/file"] }, { tuple: [":verify", ":verify_peer"] }]]}
|
||||
]
|
||||
const expectedResult = {
|
||||
':enabled': false,
|
||||
':host': 'localhost',
|
||||
':port': 389,
|
||||
':tlsopts': ['test', 'test1'],
|
||||
':sslopts': { ':cacertfile': "path/to/file", ':verify': ":verify_peer" }
|
||||
}
|
||||
|
||||
const result = parseTuples(tuples, ':ldap')
|
||||
expect(_.isEqual(expectedResult, result)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('parse rate limiters', () => {
|
||||
|
@ -35,6 +51,7 @@ describe('Parse tuples', () => {
|
|||
const parsed = parseTuples(tuples, ':manifest')
|
||||
expect(typeof parsed).toBe('object')
|
||||
expect(':icons' in parsed).toBeTruthy()
|
||||
expect('id' in parsed[':icons'][0][0]).toBeTruthy()
|
||||
|
||||
const result = parsed[':icons'].map(icon => {
|
||||
const iconWithoutId = icon.map(el => {
|
||||
|
@ -45,4 +62,35 @@ describe('Parse tuples', () => {
|
|||
})
|
||||
expect(_.isEqual(expectedResult, result)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('parse retries', () => {
|
||||
const tuples = [
|
||||
{ tuple: [':retries', [
|
||||
{ tuple: [":federator_incoming", 5] },
|
||||
{ tuple: [":federator_outgoing", 10] }
|
||||
]]}
|
||||
]
|
||||
|
||||
const parsed = parseTuples(tuples, ':workers')
|
||||
expect(typeof parsed).toBe('object')
|
||||
expect(':retries' in parsed).toBeTruthy()
|
||||
expect(Array.isArray(parsed[':retries'])).toBeTruthy()
|
||||
expect(':federator_incoming' in parsed[':retries'][0]).toBeTruthy()
|
||||
expect('id' in parsed[':retries'][0][':federator_incoming']).toBeTruthy()
|
||||
expect(parsed[':retries'][0][':federator_incoming']['value']).toEqual(5)
|
||||
})
|
||||
|
||||
it('parse objects', () => {
|
||||
const tuples = [
|
||||
{ tuple: [":pleroma_fe", { ':alwaysShowSubjectInput': true, ':redirectRootNoLogin': "/main/all" }]},
|
||||
{ tuple: [":masto_fe", { ':showInstanceSpecificPanel': true }]}
|
||||
]
|
||||
const expectedResult = {
|
||||
':masto_fe': { ':showInstanceSpecificPanel': true },
|
||||
':pleroma_fe': { ':alwaysShowSubjectInput': true, ':redirectRootNoLogin': "/main/all" }
|
||||
}
|
||||
|
||||
const result = parseTuples(tuples, ":frontend_configurations")
|
||||
expect(_.isEqual(expectedResult, result)).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue