Fix create slug bug

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2021-03-29 19:06:57 +02:00
parent d27e901e72
commit a127f35018
2 changed files with 21 additions and 0 deletions

View File

@ -19,6 +19,11 @@ const mergeParams = (refParams, params) => {
const getDeleteRedirectionLink = (links, slug, rawQuery) => {
const matchingLink = links.find(({ destination }) => destination.includes(slug));
if (!matchingLink) {
return { destination: '/', search: '' };
}
const { search } = matchingLink;
const searchQueryParams = parse(search);
const currentQueryParams = parse(rawQuery.substring(1));

View File

@ -2,6 +2,22 @@ import getDeleteRedirectionLink, { mergeParams } from '../getDeleteRedirectionLi
describe('CONTENT MANAGER | Containers | CollectionTypeFormWrapper | utils ', () => {
describe('getDeleteRedirectionLink', () => {
it('should return an when no links is matching the slug', () => {
const links = [
{
destination: '/cm/foo',
search: 'page=1&pageSize=10',
},
{
destination: '/cm/bar',
search: 'page=1&pageSize=10',
},
];
const slug = 'create';
const result = getDeleteRedirectionLink(links, slug, '');
expect(result).toEqual({ destination: '/', search: '' });
});
it('should not mutate the link when the rawQuery is empty', () => {
const links = [
{