Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove immutable from 'config' state slice #4776

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ module.exports = {
'require-atomic-updates': [0],
'import/no-unresolved': [0],
'@typescript-eslint/no-non-null-assertion': [0],
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/camelcase': [0],
'@typescript-eslint/explicit-function-return-type': [0],
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, classes: true, variables: true },
Expand Down
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
2 changes: 2 additions & 0 deletions packages/netlify-cms-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"ajv-keywords": "^4.0.0",
"connected-react-router": "^6.8.0",
"copy-text-to-clipboard": "^2.0.0",
"deepmerge": "4.2.2",
"diacritics": "^1.3.0",
"fuzzy": "^0.1.1",
"gotrue-js": "^0.9.24",
Expand Down Expand Up @@ -61,6 +62,7 @@
"react-waypoint": "^9.0.3",
"react-window": "^1.8.5",
"redux": "^4.0.5",
"redux-devtools-extension": "2.13.8",
"redux-notifications": "^4.0.1",
"redux-thunk": "^2.3.0",
"sanitize-filename": "^1.6.1",
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