From 558d3bedc8c42a84671e986d6f845ce96d3e0c74 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 6 Jan 2020 13:55:55 +0700 Subject: [PATCH] Add tests for normal tuples, retries and tuples with objects --- src/store/modules/normalizers.js | 3 -- test/modules/normalizers/parseTuples.test.js | 50 +++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index e12f3cba..a4b3c872 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -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]) && diff --git a/test/modules/normalizers/parseTuples.test.js b/test/modules/normalizers/parseTuples.test.js index 9ea5fd60..46f69086 100644 --- a/test/modules/normalizers/parseTuples.test.js +++ b/test/modules/normalizers/parseTuples.test.js @@ -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() + }) })