From 07d4669fcec686d1e2888221c57cdab016f04cf3 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Mon, 6 Jan 2020 19:34:39 +0700 Subject: [PATCH] Add tests for parsing data for assets, groups and match_actor settings --- test/modules/normalizers/parseTuples.test.js | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/modules/normalizers/parseTuples.test.js b/test/modules/normalizers/parseTuples.test.js index cf695339..e7d92d05 100644 --- a/test/modules/normalizers/parseTuples.test.js +++ b/test/modules/normalizers/parseTuples.test.js @@ -153,4 +153,66 @@ describe('Parse tuples', () => { })} expect(_.isEqual(expectedResult, result)).toBeTruthy() }) + + it('parse assets settings', () => { + const tuples = [ + { tuple: [':mascots', [ + { tuple: [':pleroma_fox_tan', { ':mime_type': 'image/png', ':url': '/images/pleroma-fox-tan-smol.png'}]}, + { tuple: [':pleroma_fox_tan_shy', { ':mime_type': 'image/png', ':url': '/images/pleroma-fox-tan-shy.png'}]} + ]]}, + { tuple: [':default_mascot', ':pleroma_fox_tan']} + ] + const expectedResult = { + ':default_mascot': ':pleroma_fox_tan', + ':mascots': [ + { ':pleroma_fox_tan': { ':mime_type': 'image/png', ':url':'/images/pleroma-fox-tan-smol.png' }}, + { ':pleroma_fox_tan_shy': { ':mime_type': 'image/png', ':url':'/images/pleroma-fox-tan-shy.png' }}] + } + + const parsed = parseTuples(tuples, ':assets') + expect(typeof parsed).toBe('object') + expect(':default_mascot' in parsed).toBeTruthy() + expect(':mascots' in parsed).toBeTruthy() + + const result = { ...parsed, ':mascots': parsed[':mascots'].map(el => { + const key = Object.keys(el)[0] + const { id, ...rest } = el[key] + return { [key]: rest } + })} + expect(_.isEqual(expectedResult, result)).toBeTruthy() + }) + + it('parse groups setting in emoji group', () => { + const tuples = [{ tuple: [':groups', [{ tuple: [':Custom', ['/emoji/*.png', '/emoji/**/*.png']]}]]}] + const expectedResult = { ':groups': [{ ':Custom': { value: ['/emoji/*.png', '/emoji/**/*.png']}}] } + + const parsed = parseTuples(tuples, ':emoji') + + expect(typeof parsed).toBe('object') + expect(':groups' in parsed).toBeTruthy() + const result = { ...parsed, ':groups': parsed[':groups'].map(el => { + const key = Object.keys(el)[0] + const { id, ...rest } = el[key] + return { [key]: rest } + })} + expect(_.isEqual(expectedResult, result)).toBeTruthy() + }) + + it('parse match_actor setting in mrf_subchain group', () => { + const tuples = [{ tuple: [":match_actor", + { '~r/https:\/\/example.com/s': ["Elixir.Pleroma.Web.ActivityPub.MRF.DropPolicy"]}]}] + const expectedResult = { ":match_actor": + [{ '~r/https:\/\/example.com/s': { value: ["Elixir.Pleroma.Web.ActivityPub.MRF.DropPolicy"] }}]} + + const parsed = parseTuples(tuples, ':mrf_subchain') + + expect(typeof parsed).toBe('object') + expect(':match_actor' in parsed).toBeTruthy() + const result = { ...parsed, ':match_actor': parsed[':match_actor'].map(el => { + const key = Object.keys(el)[0] + const { id, ...rest } = el[key] + return { [key]: rest } + })} + expect(_.isEqual(expectedResult, result)).toBeTruthy() + }) })