Skip to content

Commit

Permalink
refactor: remove immutable from 'config' state slice
Browse files Browse the repository at this point in the history
  • Loading branch information
smashercosmo committed Feb 15, 2021
1 parent 95c2a62 commit 718d0f6
Show file tree
Hide file tree
Showing 40 changed files with 548 additions and 441 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 @@ -401,7 +401,7 @@ describe('gitlab backend', () => {

const entry = await backend.getEntry(
{
config: fromJS({}),
config: {},
integrations: fromJS([]),
entryDraft: fromJS({}),
mediaLibrary: fromJS({}),
Expand Down
18 changes: 18 additions & 0 deletions packages/netlify-cms-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ declare module 'netlify-cms-core' {
cms_label_prefix?: string;
squash_merges?: boolean;
proxy_url?: string;
commit_messages?: {
create?: string;
update?: string;
delete?: string;
uploadMedia?: string;
deleteMedia?: string;
openAuthoring?: string;
};
}

export interface CmsSlug {
Expand Down Expand Up @@ -386,12 +394,22 @@ declare module 'netlify-cms-core' {
media_library?: CmsMediaLibrary;
publish_mode?: CmsPublishMode;
load_config_file?: boolean;
integrations?: {
hooks: string[];
provider: string;
collections?: '*' | string[];
applicationID?: string;
apiKey?: string;
getSignedFormURL?: string;
}[];
slug?: CmsSlug;
i18n?: CmsI18nConfig;
local_backend?: boolean | CmsLocalBackend;
editor?: {
preview?: boolean;
};
error: string | undefined;
isFetching: boolean;
}

export interface InitOptions {
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { stripIndent } from 'common-tags';
import { fromJS } from 'immutable';
import {
loadConfig,
parseConfig,
Expand Down Expand Up @@ -932,13 +931,13 @@ describe('config', () => {
expect(dispatch).toHaveBeenCalledWith({ type: 'CONFIG_REQUEST' });
expect(dispatch).toHaveBeenCalledWith({
type: 'CONFIG_SUCCESS',
payload: fromJS({
payload: {
backend: { repo: 'test-repo' },
collections: [],
publish_mode: 'simple',
slug: { encoding: 'unicode', clean_accents: false, sanitize_replacement: '-' },
public_folder: '/',
}),
},
});
});

Expand All @@ -965,13 +964,13 @@ describe('config', () => {
expect(dispatch).toHaveBeenCalledWith({ type: 'CONFIG_REQUEST' });
expect(dispatch).toHaveBeenCalledWith({
type: 'CONFIG_SUCCESS',
payload: fromJS({
payload: {
backend: { repo: 'github' },
collections: [],
publish_mode: 'simple',
slug: { encoding: 'unicode', clean_accents: false, sanitize_replacement: '-' },
public_folder: '/',
}),
},
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ describe('entries', () => {

describe('validateMetaField', () => {
const state = {
config: fromJS({
config: {
slug: {
encoding: 'unicode',
clean_accents: false,
sanitize_replacement: '-',
},
}),
},
entries: fromJS([]),
};
const collection = fromJS({
Expand Down
Loading

0 comments on commit 718d0f6

Please sign in to comment.