Skip to content

Commit

Permalink
remove immutable from 'config' state slice
Browse files Browse the repository at this point in the history
  • Loading branch information
smashercosmo committed Dec 29, 2020
1 parent 6f4ea62 commit 01651ab
Show file tree
Hide file tree
Showing 35 changed files with 1,379 additions and 1,226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe('gitlab backend', () => {
},
{
backendName: 'gitlab',
config: fromJS(config),
config,
authStore,
},
);
Expand Down Expand Up @@ -399,7 +399,7 @@ describe('gitlab backend', () => {

const entry = await backend.getEntry(
{
config: fromJS({}),
config: {},
integrations: fromJS([]),
entryDraft: fromJS({}),
mediaLibrary: fromJS({}),
Expand Down
122 changes: 88 additions & 34 deletions packages/netlify-cms-core/src/__tests__/backend.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Map, List, fromJS } from 'immutable';
import {
resolveBackend,
Backend,
extractSearchFields,
expandSearchEntries,
mergeExpandedEntries,
} from '../backend';
import registry from 'Lib/registry';
import { FOLDER } from 'Constants/collectionTypes';
import { Map, List, fromJS } from 'immutable';
import { FILES } from '../constants/collectionTypes';
import registry from '../lib/registry';
import { FOLDER, FILES } from '../constants/collectionTypes';
import { defaultState as defaultConfig } from '../reducers/config';

jest.mock('Lib/registry');
jest.mock('../lib/registry');
jest.mock('netlify-cms-lib-util');
jest.mock('../lib/urlHelper');

Expand All @@ -22,13 +22,11 @@ describe('Backend', () => {
registry.getBackend.mockReturnValue({
init: jest.fn(),
});
backend = resolveBackend(
Map({
backend: Map({
name: 'git-gateway',
}),
}),
);
backend = resolveBackend({
backend: {
name: 'git-gateway',
},
});
});

it('filters string values', () => {
Expand Down Expand Up @@ -133,9 +131,14 @@ describe('Backend', () => {
const implementation = {
init: jest.fn(() => implementation),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

const collection = Map({
name: 'posts',
Expand All @@ -155,9 +158,14 @@ describe('Backend', () => {
const implementation = {
init: jest.fn(() => implementation),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

const collection = Map({
name: 'posts',
Expand All @@ -177,9 +185,14 @@ describe('Backend', () => {
const implementation = {
init: jest.fn(() => implementation),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

const collection = Map({
name: 'posts',
Expand Down Expand Up @@ -218,9 +231,14 @@ describe('Backend', () => {
const implementation = {
init: jest.fn(() => implementation),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

const collection = Map({
name: 'posts',
Expand Down Expand Up @@ -268,9 +286,14 @@ describe('Backend', () => {
const implementation = {
init: jest.fn(() => implementation),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

backend.entryToRaw = jest.fn().mockReturnValue('');

Expand All @@ -295,9 +318,14 @@ describe('Backend', () => {
const implementation = {
init: jest.fn(() => implementation),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

backend.entryToRaw = jest.fn().mockReturnValue('content');

Expand Down Expand Up @@ -334,10 +362,15 @@ describe('Backend', () => {
init: jest.fn(() => implementation),
persistMedia: jest.fn().mockResolvedValue(persistMediaResult),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const user = { login: 'login', name: 'name' };
const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });
backend.currentUser = jest.fn().mockResolvedValue(user);

const file = { path: 'static/media/image.png' };
Expand Down Expand Up @@ -365,9 +398,15 @@ describe('Backend', () => {
.mockResolvedValueOnce('---\ntitle: "Hello World"\n---\n'),
unpublishedEntryMediaFile: jest.fn().mockResolvedValueOnce({ id: '1' }),
};
const config = Map({ media_folder: 'static/images' });
const config = {
...defaultConfig,
media_folder: 'static/images',
backend: {
name: 'github',
},
};

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

const collection = fromJS({
name: 'posts',
Expand Down Expand Up @@ -412,7 +451,12 @@ describe('Backend', () => {
const { sanitizeSlug } = require('../lib/urlHelper');
sanitizeSlug.mockReturnValue('some-post-title');

const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const implementation = {
init: jest.fn(() => implementation),
Expand All @@ -436,7 +480,7 @@ describe('Backend', () => {
title: 'some post title',
});

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

await expect(backend.generateUniqueSlug(collection, entry, Map({}), [])).resolves.toBe(
'sub_dir/some-post-title',
Expand All @@ -448,7 +492,12 @@ describe('Backend', () => {
sanitizeSlug.mockReturnValue('some-post-title');
sanitizeChar.mockReturnValue('-');

const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

const implementation = {
init: jest.fn(() => implementation),
Expand All @@ -475,7 +524,7 @@ describe('Backend', () => {
title: 'some post title',
});

const backend = new Backend(implementation, { config, backendName: 'github' });
const backend = new Backend(implementation, { config, backendName: config.backend.name });

await expect(backend.generateUniqueSlug(collection, entry, Map({}), [])).resolves.toBe(
'sub_dir/some-post-title-1',
Expand Down Expand Up @@ -585,11 +634,16 @@ describe('Backend', () => {
const implementation = {
init: jest.fn(() => implementation),
};
const config = Map({});
const config = {
...defaultConfig,
backend: {
name: 'github',
},
};

let backend;
beforeEach(() => {
backend = new Backend(implementation, { config, backendName: 'github' });
backend = new Backend(implementation, { config, backendName: config.backend.name });
backend.listAllEntries = jest.fn(collection => {
if (collection.get('name') === 'posts') {
return Promise.resolve(posts);
Expand Down
Loading

0 comments on commit 01651ab

Please sign in to comment.