From 1dca4f638041141ce386c1fd061644a1673074f7 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> Date: Fri, 20 Jan 2023 15:19:45 +0530 Subject: [PATCH 01/18] added tests for tags/actions and websocketlogs/reducer --- .gitignore | 4 +- docker-compose.yml | 21 +- studio/{ .dockerignore => .dockerignore} | 0 studio/src/__tests__/actions/tags.js | 23 ++- studio/src/__tests__/reducers/webhooks.js | 1 + studio/src/__tests__/reducers/webhookslogs.js | 183 ++++++++++++++++++ studio/src/actions/tags.js | 6 +- studio/src/constants/webhooklogs.js | 2 +- 8 files changed, 223 insertions(+), 17 deletions(-) rename studio/{ .dockerignore => .dockerignore} (100%) create mode 100644 studio/src/__tests__/reducers/webhookslogs.js diff --git a/.gitignore b/.gitignore index af991e30c..06ad708d3 100644 --- a/.gitignore +++ b/.gitignore @@ -186,4 +186,6 @@ server/server *.db dist/ -*.sqlite \ No newline at end of file +*.sqlite + +volumes/postgres/ diff --git a/docker-compose.yml b/docker-compose.yml index c9d71c30f..19a22cf63 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - "5432:5432" volumes: - ./pg-init-scripts:/docker-entrypoint-initdb.d - - ~/factly/dega/postgresql:/var/lib/postgresql/data/ + - ./volumes/postgres:/var/lib/postgresql/data/ environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres @@ -165,7 +165,7 @@ services: image: oryd/keto:v0.9.0-alpha.0 ports: - "4466:4466" # read - - "4467:4467" # write + - "4467:4467" # write - "4468:4468" # metric environment: - LOG_LEVEL=debug @@ -253,7 +253,7 @@ services: - KAVACH_KETO_READ_API_URL=http://keto:4466 - KAVACH_KETO_WRITE_API_URL=http://keto:4467 - KAVACH_KRATOS_ADMIN_URL=http://kratos:4434 - - KAVACH_KRATOS_PUBLIC_URL=http://kratos:4433 + - KAVACH_KRATOS_PUBLIC_URL=http://kratos:4433 - KAVACH_MODE=development - KAVACH_USE_SQLITE=false - KAVACH_SQLITE_DB_PATH=kavach.db @@ -297,7 +297,7 @@ services: - KAVACH_KETO_READ_API_URL=http://keto:4466 - KAVACH_KETO_WRITE_API_URL=http://keto:4467 - KAVACH_KRATOS_ADMIN_URL=http://kratos:4434 - - KAVACH_KRATOS_PUBLIC_URL=http://kratos:4433 + - KAVACH_KRATOS_PUBLIC_URL=http://kratos:4433 - KAVACH_MODE=development - KAVACH_USE_SQLITE=false - KAVACH_SQLITE_DB_PATH=kavach.db @@ -316,7 +316,12 @@ services: - KAVACH_ENABLE_IMGPROXY=false - KAVACH_DYNAMIC_EMAIL_ENABLED=true - KAVACH_BUCKET_NAME=login.factly.in - entrypoint: ["/bin/sh", "-c" , "/app/kavach-server migrate && /app/kavach-server create-super-org"] + entrypoint: + [ + "/bin/sh", + "-c", + "/app/kavach-server migrate && /app/kavach-server create-super-org", + ] networks: - dega @@ -328,7 +333,7 @@ services: target: /app/public/config.js environment: - - PUBLIC_URL=http://127.0.0.1:4455/.factly/kavach/web + - PUBLIC_URL=http://127.0.0.1:4455/.factly/kavach/web - REACT_APP_PUBLIC_URL='http://127.0.0.1:4455/.factly/kavach/web'; - REACT_APP_KAVACH_TITLE='FACTLY'; - REACT_APP_COMPANION_URL='http://127.0.0.1:3020'; @@ -338,7 +343,7 @@ services: - REACT_APP_DISABLE_REGISTRATION=false; - REACT_APP_REDIRECT_SINGLE_APPLICATION_USERS=true; - REACT_APP_LOGO_URL='https://images.factly.in/login/applications/logos/factly.png?rs:fill/h:60'; - - REACT_APP_ENABLE_IMGPROXY=false; + - REACT_APP_ENABLE_IMGPROXY=false; restart: unless-stopped networks: - dega @@ -479,7 +484,7 @@ services: volumes: - type: bind source: ./api - target: /app + target: /appendonly restart: unless-stopped networks: - dega diff --git a/studio/ .dockerignore b/studio/.dockerignore similarity index 100% rename from studio/ .dockerignore rename to studio/.dockerignore diff --git a/studio/src/__tests__/actions/tags.js b/studio/src/__tests__/actions/tags.js index 6a050c3de..24c9258a3 100644 --- a/studio/src/__tests__/actions/tags.js +++ b/studio/src/__tests__/actions/tags.js @@ -18,6 +18,7 @@ const initialState = { }; describe('tags actions', () => { + // loading actions it('should create an action to set loading to true', () => { const startLoadingAction = { type: types.SET_TAGS_LOADING, @@ -33,6 +34,8 @@ describe('tags actions', () => { }; expect(actions.stopTagsLoading()).toEqual(stopLoadingAction); }); + + // addtags it('should create an action to add tags list', () => { const data = [ { id: 1, name: 'tester 1' }, @@ -45,6 +48,8 @@ describe('tags actions', () => { }; expect(actions.addTags(data)).toEqual(addTagsAction); }); + + // add tags request it('should create an action to add tags request', () => { const data = [{ query: 'query' }]; const addTagsRequestAction = { @@ -53,12 +58,16 @@ describe('tags actions', () => { }; expect(actions.addTagsRequest(data)).toEqual(addTagsRequestAction); }); + + // reset tags it('should create an action to reset tags', () => { const resetTagsRequestAction = { type: types.RESET_TAGS, }; expect(actions.resetTags()).toEqual(resetTagsRequestAction); }); + + // fetch tags it('should create actions to fetch tags success', () => { const query = { page: 1, limit: 5 }; const tags = [{ id: 1, name: 'Tag' }]; @@ -72,7 +81,7 @@ describe('tags actions', () => { }, { type: types.ADD_TAGS, - payload: [{ id: 1, name: 'Tag' }], + payload: tags, }, { type: types.ADD_TAGS_REQUEST, @@ -92,7 +101,8 @@ describe('tags actions', () => { store .dispatch(actions.getTags(query)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.get).toHaveBeenCalledWith(types.TAGS_API, { + + expect(axios.get).toHaveBeenCalledWith(types.TAGS_API, { params: query, }); }); @@ -131,7 +141,7 @@ describe('tags actions', () => { }); it('should create actions to get tag by id success', () => { const id = 1; - const tag = { id, name: 'Tag' }; + const tag = { id, name: 'Tag'}; const resp = { data: tag }; axios.get.mockResolvedValue(resp); @@ -142,7 +152,7 @@ describe('tags actions', () => { }, { type: types.GET_TAG, - payload: { id, name: 'Tag' }, + payload: { id, name: 'Tag', description: { json: undefined, html: undefined } }, }, { type: types.SET_TAGS_LOADING, @@ -187,6 +197,7 @@ describe('tags actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.get).toHaveBeenCalledWith(types.TAGS_API + '/' + id); }); + it('should not create actions for fetching tag when spaceID is 0 ', () => { const query = { page: 1, limit: 5 }; const expectedActions = []; @@ -194,6 +205,7 @@ describe('tags actions', () => { store.dispatch(actions.getTags(query)); expect(store.getActions()).toEqual(expectedActions); }); + it('should create actions to create tag success', () => { const tag = { name: 'Tag' }; const resp = { data: tag }; @@ -224,6 +236,7 @@ describe('tags actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.post).toHaveBeenCalledWith(types.TAGS_API, tag); }); + it('should create actions to create tag failure', () => { const tag = { name: 'Tag' }; const errorMessage = 'Failed to create tag'; @@ -263,7 +276,7 @@ describe('tags actions', () => { }, { type: types.UPDATE_TAG, - payload: { id: 1, name: 'Tag' }, + payload: tag, }, { type: ADD_NOTIFICATION, diff --git a/studio/src/__tests__/reducers/webhooks.js b/studio/src/__tests__/reducers/webhooks.js index 65c279357..8038208d0 100644 --- a/studio/src/__tests__/reducers/webhooks.js +++ b/studio/src/__tests__/reducers/webhooks.js @@ -100,6 +100,7 @@ describe('webhooks reducer', () => { loading: true, }); }); + it('should handle ADD_WEBHOOKS', () => { expect( reducer(initialState, { diff --git a/studio/src/__tests__/reducers/webhookslogs.js b/studio/src/__tests__/reducers/webhookslogs.js new file mode 100644 index 000000000..36cf18a8a --- /dev/null +++ b/studio/src/__tests__/reducers/webhookslogs.js @@ -0,0 +1,183 @@ +import webhooklogsReducer from '../../reducers/webhooklogsReducer'; +import * as types from '../../constants/webhooklogs'; + +const initialState = { + req: [], + details: {}, + loading: true, +}; + +describe('webhooklogsReducer', () => { + it('should return the initial state', () => { + expect(webhooklogsReducer(undefined, {})).toEqual(initialState); + }); + + it('should handle RESET_WEBHOOKS', () => { + expect( + webhooklogsReducer( + { + req: [{ data: [1, 2, 3], query: { page: 1, limit: 5 }, total: 3 }], + details: [{ id: 1, name: 'webhook' }], + loading: false, + }, + { + type: types.RESET_WEBHOOKLOGS, + payload: {}, + }, + ), + ).toEqual(initialState); + }); + + it('should handle SET_WEBHOOKLOGS_LOADING', () => { + expect(webhooklogsReducer(initialState, { + type: types.SET_WEBHOOKLOGS_LOADING, + payload: false, + })).toEqual({ + req: [], + details: {}, + loading: false, + }); + + expect(webhooklogsReducer(initialState, { + type: types.SET_WEBHOOKLOGS_LOADING, + payload: true, + })).toEqual({ + req: [], + details: {}, + loading: true, + }) + }); + + it('should handle ADD_WEBHOOKLOGS_REQUEST', () => { + expect( + webhooklogsReducer(initialState, { + type: types.ADD_WEBHOOKLOGS_REQUEST, + payload: { + data: [1, 2, 3], + query: { page: 1, limit: 5 }, + total: 3, + }, + }), + ).toEqual({ + req: [{ data: [1, 2, 3], query: { page: 1, limit: 5 }, total: 3 }], + details: {}, + loading: true, + }); + }); + + it('should handle ADD_WEBHOOKLOGS_REQUEST when req already exists', () => { + expect( + webhooklogsReducer( + { + req: [{ data: [1, 2], query: { page: 1, limit: 5 }, total: 2 }], + details: {}, + loading: true, + }, + { + type: types.ADD_WEBHOOKLOGS_REQUEST, + payload: { + data: [1, 2, 3], + query: { page: 1, limit: 5 }, + total: 3, + }, + }, + ), + ).toEqual({ + req: [{ data: [1, 2, 3], query: { page: 1, limit: 5 }, total: 3 }], + details: {}, + loading: true, + }); + }); + + it('should handle ADD_WEBHOOKLOGS', () => { + expect( + webhooklogsReducer(initialState, { + type: types.ADD_WEBHOOKLOGS, + payload: [ + { id: 1, name: 'Webhook 1' }, + { id: 2, name: 'Webhook 2' }, + ], + }), + ).toEqual({ + req: [], + details: { 1: { id: 1, name: 'Webhook 1' }, 2: { id: 2, name: 'Webhook 2' } }, + loading: true, + }); + }); + + it('should handle empty payload ADD_WEBHOOKLOGS', () => { + expect( + webhooklogsReducer(initialState, { + type: types.ADD_WEBHOOKLOGS, + payload: [], + }), + ).toEqual({ + req: [], + details: {}, + loading: true, + }); + }); + + it('should handle ADD_WEBHOOKLOGS', () => { + expect( + webhooklogsReducer(initialState, { + type: types.ADD_WEBHOOKLOGS, + payload: [{ id: 1, name: 'new webhook' }], + }), + ).toEqual({ + req: [], + details: { 1: { id: 1, name: 'new webhook' } }, + loading: true, + }); + }); + + it('should handle ADD_WEBHOOKLOGS when details is non-empty', () => { + expect( + webhooklogsReducer( + { + req: [], + details: { 1: { id: 1, name: 'existing webhook' } }, + loading: false, + }, + { + type: types.ADD_WEBHOOKLOGS, + payload: [{ id: 2, name: 'new webhook' }], + }, + ), + ).toEqual({ + req: [], + details: { + 1: { id: 1, name: 'existing webhook' }, + 2: { id: 2, name: 'new webhook' }, + }, + loading: false, + }); + }); + + it('should handle ADD_WEBHOOKLOGS when already exists', () => { + expect( + webhooklogsReducer( + { + req: [], + details: { + 1: { id: 1, name: 'existing webhook' }, + 2: { id: 2, name: 'new webhook' }, + }, + loading: false, + }, + { + type: types.ADD_WEBHOOKLOGS, + payload: [{ id: 2, name: 'updated webhook' }], + }, + ), + ).toEqual({ + req: [], + details: { + 1: { id: 1, name: 'existing webhook' }, + 2: { id: 2, name: 'updated webhook' }, + }, + loading: false, + }); + }); + +}); diff --git a/studio/src/actions/tags.js b/studio/src/actions/tags.js index 777d78340..94380c3d5 100644 --- a/studio/src/actions/tags.js +++ b/studio/src/actions/tags.js @@ -118,6 +118,7 @@ export const deleteTag = (id) => { }; }; +//? tested export const loadingTags = () => ({ type: SET_TAGS_LOADING, payload: true, @@ -133,16 +134,17 @@ export const addTag = (type, payload) => ({ payload, }); +// ?tested export const addTags = (data) => ({ type: ADD_TAGS, payload: data, }); - +// ?tested export const addTagsRequest = (data) => ({ type: ADD_TAGS_REQUEST, payload: data, }); - +// ?tested export const resetTags = () => ({ type: RESET_TAGS, }); diff --git a/studio/src/constants/webhooklogs.js b/studio/src/constants/webhooklogs.js index 64cc3d3be..de7017cbe 100644 --- a/studio/src/constants/webhooklogs.js +++ b/studio/src/constants/webhooklogs.js @@ -3,4 +3,4 @@ export const ADD_WEBHOOKLOG = 'ADD_WEBHOOKLOG'; export const ADD_WEBHOOKLOGS = 'ADD_WEBHOOKLOGS'; export const ADD_WEBHOOKLOGS_REQUEST = 'ADD_WEBHOOKLOGS_REQUEST'; export const RESET_WEBHOOKLOGS = 'RESET_WEBHOOKLOGS'; -export const SET_WEBHOOKLOGS_LOADING = 'SET_WEBHOOKLOGS_LOADING'; \ No newline at end of file +export const SET_WEBHOOKLOGS_LOADING = 'SET_WEBHOOKLOGS_LOADING'; From 8d700769c37e3def42489f295ecea4683d71673b Mon Sep 17 00:00:00 2001 From: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> Date: Fri, 20 Jan 2023 19:43:21 +0530 Subject: [PATCH 02/18] fixed broken tests for actions/claimants.js --- studio/src/__tests__/actions/categories.js | 34 +++++++---- studio/src/__tests__/actions/claimants.js | 68 +++++++++++++--------- studio/src/__tests__/actions/tags.js | 45 ++++++++++++-- studio/src/actions/claimants.js | 24 ++++++++ 4 files changed, 128 insertions(+), 43 deletions(-) diff --git a/studio/src/__tests__/actions/categories.js b/studio/src/__tests__/actions/categories.js index 3fdd9755b..fc29e68da 100644 --- a/studio/src/__tests__/actions/categories.js +++ b/studio/src/__tests__/actions/categories.js @@ -20,6 +20,7 @@ const initialState = { }; describe('categories actions', () => { + // set loading to true it('should create an action to set loading to true', () => { const startLoadingAction = { type: types.SET_CATEGORIES_LOADING, @@ -27,6 +28,7 @@ describe('categories actions', () => { }; expect(actions.loadingCategories()).toEqual(startLoadingAction); }); + // set loading to false it('should create an action to set loading to false', () => { const stopLoadingAction = { type: types.SET_CATEGORIES_LOADING, @@ -34,6 +36,7 @@ describe('categories actions', () => { }; expect(actions.stopCategoriesLoading()).toEqual(stopLoadingAction); }); + // add categories list it('should create an action to add categories list', () => { const data = [ { id: 1, name: 'tester 1' }, @@ -46,6 +49,7 @@ describe('categories actions', () => { }; expect(actions.addCategoriesList(data)).toEqual(addCategoriesAction); }); + // to add categories request it('should create an action to add categories request', () => { const data = [{ query: 'query' }]; const addCategoriesRequestAction = { @@ -54,12 +58,14 @@ describe('categories actions', () => { }; expect(actions.addCategoriesRequest(data)).toEqual(addCategoriesRequestAction); }); + it('should create an action to reset categories', () => { const resetCategoriesRequestAction = { type: types.RESET_CATEGORIES, }; expect(actions.resetCategories()).toEqual(resetCategoriesRequestAction); }); + it('should create actions to fetch categories success', () => { const query = { page: 1, limit: 5 }; const categories = [{ id: 1, name: 'Category' }]; @@ -77,7 +83,9 @@ describe('categories actions', () => { }, { type: types.ADD_CATEGORIES, - payload: [{ id: 1, name: 'Category', medium: undefined }], + payload: [ + { id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } } + ], }, { type: types.ADD_CATEGORIES_REQUEST, @@ -114,7 +122,7 @@ describe('categories actions', () => { }, { type: types.ADD_CATEGORIES, - payload: [{ id: 1, name: 'Category', medium: undefined }], + payload: [{ id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, }, }], }, { type: types.ADD_CATEGORIES_REQUEST, @@ -152,7 +160,7 @@ describe('categories actions', () => { }, { type: types.ADD_CATEGORIES, - payload: [{ id: 1, name: 'Category', medium: 3 }], + payload: [{ id: 1, name: 'Category', medium: 3, description: { "html": undefined, "json": undefined, }, }], }, { type: types.ADD_CATEGORIES_REQUEST, @@ -260,7 +268,7 @@ describe('categories actions', () => { }, { type: types.GET_CATEGORY, - payload: { id, name: 'Category', medium: undefined }, + payload: { id, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, }, { type: types.SET_CATEGORIES_LOADING, @@ -292,7 +300,7 @@ describe('categories actions', () => { }, { type: types.GET_CATEGORY, - payload: { id, name: 'Category', medium: 1 }, + payload: { id, name: 'Category', medium: 1, description: { "html": undefined, "json": undefined, } }, }, { type: types.SET_CATEGORIES_LOADING, @@ -306,6 +314,7 @@ describe('categories actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.get).toHaveBeenCalledWith(types.CATEGORIES_API + '/' + id); }); + it('should create actions to create category success', () => { const category = { name: 'Category' }; const resp = { data: category }; @@ -336,6 +345,7 @@ describe('categories actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.post).toHaveBeenCalledWith(types.CATEGORIES_API, category); }); + it('should create actions to create category failure', () => { const category = { name: 'Category' }; const errorMessage = 'Failed to create category'; @@ -375,7 +385,7 @@ describe('categories actions', () => { }, { type: types.UPDATE_CATEGORY, - payload: { id: 1, name: 'Category', medium: undefined }, + payload: { id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, }, { type: ADD_NOTIFICATION, @@ -415,7 +425,7 @@ describe('categories actions', () => { }, { type: types.UPDATE_CATEGORY, - payload: { id: 1, name: 'Category', medium: 4 }, + payload: { id: 1, name: 'Category', medium: 4, description: { "html": undefined, "json": undefined, } }, }, { type: ADD_NOTIFICATION, @@ -537,8 +547,8 @@ describe('categories actions', () => { { type: types.ADD_CATEGORIES, payload: [ - { id: 1, name: 'Category', medium: undefined }, - { id: 2, name: 'Category', medium: undefined }, + { id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, + { id: 2, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, ], }, ]; @@ -550,7 +560,7 @@ describe('categories actions', () => { it('should create actions to add categories list', () => { const medium = { id: 4, name: 'mediumm' }; const categories = [ - { id: 1, name: 'Category' }, + { id: 1, name: 'Category' }, { id: 2, name: 'Category', medium: medium }, ]; @@ -562,8 +572,8 @@ describe('categories actions', () => { { type: types.ADD_CATEGORIES, payload: [ - { id: 1, name: 'Category', medium: undefined }, - { id: 2, name: 'Category', medium: 4 }, + { id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, + { id: 2, name: 'Category', medium: 4, description: { "html": undefined, "json": undefined, } }, ], }, ]; diff --git a/studio/src/__tests__/actions/claimants.js b/studio/src/__tests__/actions/claimants.js index 5da30d0df..61913a6fc 100644 --- a/studio/src/__tests__/actions/claimants.js +++ b/studio/src/__tests__/actions/claimants.js @@ -59,7 +59,7 @@ describe('claimants actions', () => { }; expect(actions.resetClaimants()).toEqual(resetClaimantsRequestAction); }); - it('should create actions to fetch claimants success without media', () => { + it('should create actions to fetch claimants success without media and description', () => { const query = { page: 1, limit: 5 }; const claimants = [{ id: 1, name: 'Claimant' }]; const resp = { data: { nodes: claimants, total: 1 } }; @@ -76,7 +76,7 @@ describe('claimants actions', () => { }, { type: types.ADD_CLAIMANTS, - payload: [{ id: 1, name: 'Claimant', medium: undefined }], + payload: [{ id: 1, name: 'Claimant', medium: undefined, description: { "html": undefined, "json": undefined, } }], }, { type: types.ADD_CLAIMANTS_REQUEST, @@ -100,12 +100,12 @@ describe('claimants actions', () => { params: query, }); }); - it('should create actions to fetch claimants success not all with media', () => { + it('should create actions to fetch claimants success not all with media and not all with description and html', () => { const query = { page: 1, limit: 5 }; const claimants = [ { id: 1, name: 'Claimant', medium: { id: 11, medium: 'Medium' } }, - { id: 2, name: 'Claimant 2' }, + { id: 2, name: 'Claimant 2', description: { "hello": "test" }, description_html: "
test
", }, ]; const resp = { data: { nodes: episodes, total: 1 } }; @@ -73,7 +75,7 @@ describe('episodes actions', () => { }, { type: types.ADD_EPISODES, - payload: [{ id: 1, title: 'Episode', podcast: 1 }], + payload: [{ id: 1, title: 'Episode', podcast: 1, description: { json: { "hello": "test" }, html: "test
" }, }], }, { type: types.ADD_EPISODES_REQUEST, @@ -131,7 +133,7 @@ describe('episodes actions', () => { it('should create actions to get episode by id success', () => { const id = 1; const podcast = { id: 1 }; - const episode = { id, title: 'Episode', podcast: podcast }; + const episode = { id, title: 'Episode', podcast: podcast, description: { "hello": "test" }, description_html: "test
" }; const resp = { data: episode }; axios.get.mockResolvedValue(resp); @@ -146,7 +148,7 @@ describe('episodes actions', () => { }, { type: types.GET_EPISODE, - payload: { id, title: 'Episode', podcast: 1 }, + payload: { id, title: 'Episode', podcast: 1, description: { json: { "hello": "test" }, html: "test
" }, }, }, { type: types.SET_EPISODES_LOADING, @@ -191,7 +193,7 @@ describe('episodes actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.get).toHaveBeenCalledWith(types.EPISODES_API + '/' + id); }); - it('should create actions to get episode by id with no podcast ', () => { + it('should create actions to get episode by id with no podcast no description', () => { const id = 1; const podcast = {}; const episode = { id, title: 'Episode', podcast: podcast }; @@ -205,7 +207,7 @@ describe('episodes actions', () => { }, { type: types.GET_EPISODE, - payload: { id, title: 'Episode' }, + payload: { id, title: 'Episode', podcast: undefined, description: { json: undefined, html: undefined }, }, }, { type: types.SET_EPISODES_LOADING, @@ -278,7 +280,8 @@ describe('episodes actions', () => { }); it('should create actions to update episode success', () => { const podcast = { id: 1 }; - const episode = { id: 1, title: 'Episode', podcast: podcast }; + const episode = { id: 1, title: 'Episode', podcast: podcast, description: { json: { "hello": "test" }, html: "test
" } + }; const resp = { data: episode }; axios.put.mockResolvedValue(resp); @@ -293,7 +296,7 @@ describe('episodes actions', () => { }, { type: types.UPDATE_EPISODE, - payload: { id: 1, title: 'Episode', podcast: 1 }, + payload: { id: 1, title: 'Episode', podcast: 1, description: { json: { "hello": "test" }, html: "test
" } }, }, { type: ADD_NOTIFICATION, @@ -347,9 +350,10 @@ describe('episodes actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.EPISODES_API + '/1', episode); }); - it('should create actions to update episode success without podcast', () => { + it('should create actions to update episode success without podcast and without description ', () => { const podcast = {}; - const episode = { id: 1, title: 'Episode', podcast: podcast }; + const description = {json: undefined, html: undefined}; + const episode = { id: 1, title: 'Episode', podcast: podcast, description: description }; const resp = { data: episode }; axios.put.mockResolvedValue(resp); @@ -360,7 +364,7 @@ describe('episodes actions', () => { }, { type: types.UPDATE_EPISODE, - payload: { id: 1, title: 'Episode' }, + payload: { id: 1, title: 'Episode', podcast: undefined, description: { json: undefined, html: undefined } }, }, { type: ADD_NOTIFICATION, diff --git a/studio/src/actions/claims.js b/studio/src/actions/claims.js index c8e76428b..113819c19 100644 --- a/studio/src/actions/claims.js +++ b/studio/src/actions/claims.js @@ -55,6 +55,8 @@ export const getClaims = (query) => { addClaimsList( response.data.nodes.map((claim) => { claim.description = { json: claim.description, html: claim.description_html }; + // !here description_html is not removed and has the same issue explained in "./claimants.js" + delete claim.description_html return { ...claim, claimant: claim.claimant.id, rating: claim.rating.id }; }), ), @@ -83,6 +85,8 @@ export const getClaim = (id) => { .then((response) => { let claim = response.data; claim.description = { json: claim.description, html: claim.description_html }; + // ! here also we need to delete description_html + delete claim.description_html dispatch(addClaimants([claim.claimant])); dispatch(addRatings([claim.rating])); @@ -127,7 +131,27 @@ export const updateClaim = (data) => { .put(CLAIMS_API + '/' + data.id, data) .then((response) => { let claim = response.data; - claim.description = { json: claim.description, html: claim.description_html }; + //! this needs to modified claim object current structure + //! claim = { + //! ... + //! description: { + //! json: {} + //! html: .. + //! } + //! } + // claim.description = { json: claim.description, html: claim.description_html }; + //! after above it becomes + //! claim ={ + //! ... + //! description: { + //! json: { + //! json: {} + //! html: ... + //! } + //! html: .. + //! } + //! ... + //! } dispatch(addClaimants([claim.claimant])); dispatch(addRatings([claim.rating])); diff --git a/studio/src/actions/episodes.js b/studio/src/actions/episodes.js index de4797880..ed1f2f664 100644 --- a/studio/src/actions/episodes.js +++ b/studio/src/actions/episodes.js @@ -51,6 +51,8 @@ export const getEpisodes = (query) => { addEpisodes( response.data.nodes.map((episode) => { episode.description = { json: episode.description, html: episode.description_html }; + // !here we need to delete the description_html field + delete episode.description_html; return { ...episode, podcast: episode.podcast.id }; }), ), @@ -79,6 +81,8 @@ export const getEpisode = (id) => { .then((response) => { let episode = response.data; episode.description = { json: episode.description, html: episode.description_html }; + // ! here we need to delete the description_html field also + delete episode.description_html; if (episode.podcast.id > 0) dispatch(addPodcasts([episode.podcast])); dispatch(addEpisode(GET_EPISODE, { ...episode, podcast: episode.podcast.id })); }) @@ -113,7 +117,27 @@ export const updateEpisode = (data) => { .put(EPISODES_API + '/' + data.id, data) .then((response) => { let episode = response.data; - episode.description = { json: episode.description, html: episode.description_html }; + //! this needs to modified claim object current structure + //! episode = { + //! ... + //! description: { + //! json: {} + //! html: .. + //! } + //! } + // episode.description = { json: episode.description, html: episode.description_html };= + //! after above it becomes + //! episode ={ + //! ... + //! description: { + //! json: { + //! json: {} + //! html: ... + //! } + //! html: .. + //! } + //! ... + //! } if (episode.podcast.id > 0) dispatch(addPodcasts([episode.podcast])); dispatch(addEpisode(UPDATE_EPISODE, { ...episode, podcast: episode.podcast.id })); dispatch(addSuccessNotification('Episode updated')); From 8c9d8ddbc250a87a8db1bfd0e65d7d3253982b87 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> Date: Tue, 24 Jan 2023 14:03:58 +0530 Subject: [PATCH 04/18] added tests for actions/ pages categories claimants roles pages --- studio/nginx/nginx.conf | 2 +- studio/src/__tests__/actions/pages.js | 146 +++++- studio/src/__tests__/actions/ratings.js | 92 ++-- studio/src/__tests__/actions/roles.js | 561 ++++++++++++++++++++++++ studio/src/actions/categories.js | 11 +- studio/src/actions/claimants.js | 2 +- studio/src/actions/pages.js | 10 +- studio/src/actions/ratings.js | 14 +- studio/src/actions/roles.js | 8 +- 9 files changed, 787 insertions(+), 59 deletions(-) create mode 100644 studio/src/__tests__/actions/roles.js diff --git a/studio/nginx/nginx.conf b/studio/nginx/nginx.conf index 2dc959bc4..40a878bce 100644 --- a/studio/nginx/nginx.conf +++ b/studio/nginx/nginx.conf @@ -4,7 +4,7 @@ server { location / { root /usr/share/nginx/html; - index index.html index.html; + index index.html index.htm; try_files $uri $uri/ /index.html; } diff --git a/studio/src/__tests__/actions/pages.js b/studio/src/__tests__/actions/pages.js index 59af349c7..9a1e39c08 100644 --- a/studio/src/__tests__/actions/pages.js +++ b/studio/src/__tests__/actions/pages.js @@ -31,7 +31,7 @@ const page1 = { { id: 22, name: 'Tag 22' }, ], categories: [ - { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' }, description: { "hello": "world" }, description_html: "hello world
" }, { id: 32, name: 'category 32' }, ], format: { id: 41, name: 'Format 1' }, @@ -154,8 +154,18 @@ describe('pages actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, description: { + json: { "hello": "world" }, + html: 'hello world
', + } + }, + { + id: 32, name: 'category 32', medium: undefined, description: { + json: undefined, + html: undefined, + } + }, ], }, { @@ -176,6 +186,10 @@ describe('pages actions', () => { authors: [11], tags: [21, 22], categories: [31, 32], + description: { + json: undefined, + html: undefined, + }, format: 41, medium: 51, }, @@ -250,7 +264,22 @@ describe('pages actions', () => { format: [42], status: 'publish', }; - const pages = [{ ...page1, status: 'publish' }]; + const page = { + id: 1, + name: 'Page 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' }, description: { "hello": "world" }, description_html: "hello world
" }, + { id: 32, name: 'category 32' }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + }; + const pages = [{ ...page, status: 'publish' }]; const resp = { data: { nodes: pages, total: 1 } }; axios.get.mockResolvedValue(resp); @@ -277,8 +306,18 @@ describe('pages actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, description: { + json: { "hello": "world" }, + html: 'hello world
', + } + }, + { + id: 32, name: 'category 32', medium: undefined, description: { + json: undefined, + html: undefined, + } + }, ], }, { @@ -300,6 +339,10 @@ describe('pages actions', () => { tags: [21, 22], categories: [31, 32], format: 41, + description: { + json: undefined, + html: undefined, + }, medium: 51, }, ], @@ -382,6 +425,10 @@ describe('pages actions', () => { categories: [], format: 41, medium: undefined, + description: { + json: undefined, + html: undefined, + }, }, ], }, @@ -411,7 +458,24 @@ describe('pages actions', () => { }); it('should create actions to get page by id success', () => { const id = 1; - const resp = { data: page1 }; + const page = { + id: 1, + name: 'Page 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' }, description: { "hello": "world" }, description_html: "hello world
" }, + { id: 32, name: 'category 32' }, + ], + description: { "hello": "world" }, + description_html: "hello world
", + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + }; + const resp = { data: page }; axios.get.mockResolvedValue(resp); const expectedActions = [ @@ -437,8 +501,13 @@ describe('pages actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, description: { + json: { "hello": "world" }, + html: "hello world
", + } + }, + { id: 32, name: 'category 32', medium: undefined, description: { json: undefined, html: undefined } }, ], }, { @@ -454,6 +523,10 @@ describe('pages actions', () => { tags: [21, 22], categories: [31, 32], format: { id: 41, name: 'Format 1' }, + description: { + json: { "hello": 'world' }, + html: 'hello world
', + }, medium: 51, }, }, @@ -549,6 +622,10 @@ describe('pages actions', () => { categories: [], format: { id: 41, name: 'Format 1' }, medium: undefined, + description: { + json: undefined, + html: undefined, + }, }, }, { @@ -564,7 +641,25 @@ describe('pages actions', () => { expect(axios.get).toHaveBeenCalledWith(types.PAGES_API + '/' + id); }); it('should create actions to create page success', () => { - const data2 = { ...page1 }; + const page = { + id: 1, + name: 'Page 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' }, description: { "hello": "world" }, description_html: "hello world
" }, + { id: 32, name: 'category 32' }, + ], + description: { "hello": "world" }, + description_html: "hello world
", + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + }; + + const data2 = { ...page }; data2.status = 'publish'; const resp = { data: data2 }; axios.post.mockResolvedValue(resp); @@ -588,8 +683,8 @@ describe('pages actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { id: 31, name: 'category 31', medium: 311, description: { json: { "hello": "world" }, html: "hello world
" } }, + { id: 32, name: 'category 32', medium: undefined, description: { json: undefined, html: undefined } }, ], }, { @@ -751,7 +846,7 @@ describe('pages actions', () => { expect(axios.post).toHaveBeenCalledWith(types.PAGES_API, page); }); it('should create actions to update page success', () => { - const data2 = { ...page1 }; + const data2 = { ...page1, description: { json: { "hello": "world" }, html: "hello world
" } }; data2.status = 'draft'; const resp = { data: data2 }; axios.put.mockResolvedValue(resp); @@ -775,8 +870,8 @@ describe('pages actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { id: 31, name: 'category 31', medium: 311, description: { json: { "hello": 'world' }, html: "hello world
" } }, + { id: 32, name: 'category 32', medium: undefined, description: { json: undefined, html: undefined } }, ], }, { @@ -798,6 +893,9 @@ describe('pages actions', () => { categories: [31, 32], format: { id: 41, name: 'Format 1' }, medium: 51, + description: { + json: { "hello": 'world' }, html: "hello world
" + }, }, }, { @@ -821,8 +919,9 @@ describe('pages actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.PAGES_API + '/1', page1); }); + it('should create actions to update page success with ready status', () => { - const data2 = { ...page1 }; + const data2 = { ...page1, description: { json: { "hello": "world" }, html: "hello world
" } }; data2.status = 'ready'; const resp = { data: data2 }; axios.put.mockResolvedValue(resp); @@ -846,8 +945,8 @@ describe('pages actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { id: 31, name: 'category 31', medium: 311, description: { json: { "hello": 'world' }, html: "hello world
" } }, + { id: 32, name: 'category 32', medium: undefined, description: { json: undefined, html: undefined } }, ], }, { @@ -869,6 +968,9 @@ describe('pages actions', () => { categories: [31, 32], format: { id: 41, name: 'Format 1' }, medium: 51, + description: { + json: { "hello": 'world' }, html: "hello world
" + }, }, }, { @@ -876,7 +978,8 @@ describe('pages actions', () => { payload: { type: 'success', title: 'Success', - message: 'Draft saved & Ready to Publish', + + message: "Draft saved & Ready to Publish", time: Date.now(), }, }, @@ -929,6 +1032,7 @@ describe('pages actions', () => { page.tags = []; page.medium = undefined; page.status = 'publish'; + page.description = { json: undefined, html: undefined} const resp = { data: page }; axios.put.mockResolvedValue(resp); @@ -965,6 +1069,10 @@ describe('pages actions', () => { format: { id: 41, name: 'Format 1' }, medium: undefined, status: 'publish', + description: { + json: undefined, + html: undefined, + }, }, }, { diff --git a/studio/src/__tests__/actions/ratings.js b/studio/src/__tests__/actions/ratings.js index 7aaf81084..556c77411 100644 --- a/studio/src/__tests__/actions/ratings.js +++ b/studio/src/__tests__/actions/ratings.js @@ -60,7 +60,7 @@ describe('ratings actions', () => { }; expect(actions.resetRatings()).toEqual(resetRatingsAction); }); - it('should create actions to fetch ratings with none having media', () => { + it('should create actions to fetch ratings with none having media and description', () => { const query = { page: 1, limit: 5 }; const ratings = [{ id: 1, name: 'Rating' }]; const resp = { data: { nodes: ratings, total: 2 } }; @@ -77,7 +77,7 @@ describe('ratings actions', () => { }, { type: types.ADD_RATINGS, - payload: [{ id: 1, name: 'Rating', medium: undefined }], + payload: [{ id: 1, name: 'Rating', medium: undefined, description: { json: undefined, html: undefined } }], }, { type: types.ADD_RATINGS_REQUEST, @@ -101,11 +101,11 @@ describe('ratings actions', () => { params: query, }); }); - it('should create actions to fetch ratings success with some having media', () => { + it('should create actions to fetch ratings success with some having media and some having description', () => { const query = { page: 1, limit: 5 }; const ratings = [ { id: 1, name: 'Rating 1', medium: { id: 10, medium: 'Medium 1' } }, - { id: 2, name: 'Rating 2' }, + { id: 2, name: 'Rating 2', description: { "hello": "test" }, description_html: "test
" }, ]; const resp = { data: { nodes: ratings, total: 2 } }; axios.get.mockResolvedValue(resp); @@ -122,8 +122,8 @@ describe('ratings actions', () => { { type: types.ADD_RATINGS, payload: [ - { id: 1, name: 'Rating 1', medium: 10 }, - { id: 2, name: 'Rating 2', medium: undefined }, + { id: 1, name: 'Rating 1', medium: 10, description: { json: undefined, html: undefined } }, + { id: 2, name: 'Rating 2', medium: undefined, description: { json: { "hello": "test" }, html: "test
" } }, ], }, { @@ -148,11 +148,11 @@ describe('ratings actions', () => { params: query, }); }); - it('should create actions to fetch ratings success with all having media', () => { + it('should create actions to fetch ratings success with all having media and all having description ', () => { const query = { page: 1, limit: 5 }; const ratings = [ - { id: 1, name: 'Rating 1', medium: { id: 10, medium: 'Medium 1' } }, - { id: 2, name: 'Rating 2', medium: { id: 20, medium: 'Medium 2' } }, + { id: 1, name: 'Rating 1', medium: { id: 10, medium: 'Medium 1' }, description: { "hello": "test1" }, description_html: "test1
" }, + { id: 2, name: 'Rating 2', medium: { id: 20, medium: 'Medium 2' }, description: { "hello": "test2" }, description_html: "test2
" }, ]; const resp = { data: { nodes: ratings, total: 2 } }; axios.get.mockResolvedValue(resp); @@ -172,8 +172,18 @@ describe('ratings actions', () => { { type: types.ADD_RATINGS, payload: [ - { id: 1, name: 'Rating 1', medium: 10 }, - { id: 2, name: 'Rating 2', medium: 20 }, + { + id: 1, name: 'Rating 1', medium: 10, description: { + json: { "hello": "test1" }, + html: "test1
", + } + }, + { + id: 2, name: 'Rating 2', medium: 20, description: { + json: { "hello": "test2" }, + html: "test2
", + } + }, ], }, { @@ -262,7 +272,7 @@ describe('ratings actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.get).toHaveBeenCalledWith(types.RATINGS_API + '/' + id); }); - it('should create actions to get rating by id without medium', () => { + it('should create actions to get rating by id without medium and description', () => { const id = 1; const rating = { id, name: 'Rating' }; const resp = { data: rating }; @@ -275,7 +285,12 @@ describe('ratings actions', () => { }, { type: types.GET_RATING, - payload: { id, name: 'Rating', medium: undefined }, + payload: { + id, name: 'Rating', medium: undefined, description: { + json: undefined, + html: undefined, + } + }, }, { type: types.SET_RATINGS_LOADING, @@ -289,10 +304,12 @@ describe('ratings actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.get).toHaveBeenCalledWith(types.RATINGS_API + '/' + id); }); - it('should create actions to get rating by id with medium', () => { + it('should create actions to get rating by id with medium and description', () => { const id = 1; const medium = { id: 1, medium: 'Medium' }; - const rating = { id, name: 'Rating', medium }; + const description = { "hello": "test" } + const description_html = "test
" + const rating = { id, name: 'Rating', medium, description, description_html }; const resp = { data: rating }; axios.get.mockResolvedValue(resp); @@ -307,7 +324,7 @@ describe('ratings actions', () => { }, { type: types.GET_RATING, - payload: { id, name: 'Rating', medium: 1 }, + payload: { id, name: 'Rating', medium: 1, description: { json: description, html: description_html } }, }, { type: types.SET_RATINGS_LOADING, @@ -378,7 +395,7 @@ describe('ratings actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.post).toHaveBeenCalledWith(types.RATINGS_API, rating); }); - it('should create actions to update rating without medium', () => { + it('should create actions to update rating without medium and description', () => { const rating = { id: 1, name: 'Rating' }; const resp = { data: rating }; axios.put.mockResolvedValue(resp); @@ -390,7 +407,7 @@ describe('ratings actions', () => { }, { type: types.UPDATE_RATING, - payload: { id: 1, name: 'Rating', medium: undefined }, + payload: { id: 1, name: 'Rating', medium: undefined, description: { json: undefined, html: undefined } }, }, { type: ADD_NOTIFICATION, @@ -413,9 +430,10 @@ describe('ratings actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.RATINGS_API + '/1', rating); }); - it('should create actions to update rating with medium', () => { + it('should create actions to update rating with medium and description', () => { const medium = { id: 4, name: 'medium' }; - const rating = { id: 1, name: 'Rating', medium: medium }; + const description = { json: { "hello": "test" }, html: "test
" } + const rating = { id: 1, name: 'Rating', medium: medium, description: description }; const resp = { data: rating }; axios.put.mockResolvedValue(resp); @@ -430,7 +448,7 @@ describe('ratings actions', () => { }, { type: types.UPDATE_RATING, - payload: { id: 1, name: 'Rating', medium: 4 }, + payload: { id: 1, name: 'Rating', medium: 4, description}, }, { type: ADD_NOTIFICATION, @@ -529,7 +547,7 @@ describe('ratings actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.delete).toHaveBeenCalledWith(types.RATINGS_API + '/1'); }); - it('should create actions to add ratings list with none having medium', () => { + it('should create actions to add ratings list with none having medium and description', () => { const ratings = [ { id: 1, name: 'Rating' }, { id: 2, name: 'Rating 2' }, @@ -543,8 +561,18 @@ describe('ratings actions', () => { { type: types.ADD_RATINGS, payload: [ - { id: 1, name: 'Rating', medium: undefined }, - { id: 2, name: 'Rating 2', medium: undefined }, + { + id: 1, name: 'Rating', medium: undefined, description: { + json: undefined, + html: undefined, + } + }, + { + id: 2, name: 'Rating 2', medium: undefined, description: { + json: undefined, + html: undefined, + } + }, ], }, ]; @@ -553,10 +581,12 @@ describe('ratings actions', () => { store.dispatch(actions.addRatings(ratings)); expect(store.getActions()).toEqual(expectedActions); }); - it('should create actions to add ratings list with some having medium', () => { + it('should create actions to add ratings list with some having medium and some having description', () => { const medium = { id: 4, name: 'medium' }; + const description = { "hello": "test" }; + const description_html = "test
"; const ratings = [ - { id: 1, name: 'Rating' }, + { id: 1, name: 'Rating', description, description_html }, { id: 2, name: 'Rating 2', medium: medium }, ]; @@ -568,8 +598,11 @@ describe('ratings actions', () => { { type: types.ADD_RATINGS, payload: [ - { id: 1, name: 'Rating', medium: undefined }, - { id: 2, name: 'Rating 2', medium: 4 }, + { + id: 1, name: 'Rating', medium: undefined, + description: { json: description, html: description_html } + }, + { id: 2, name: 'Rating 2', medium: 4, description: { json: undefined, html: undefined } }, ], }, ]; @@ -608,12 +641,13 @@ describe('ratings actions', () => { }, { type: types.ADD_RATINGS, - payload: [{ id: 1, name: 'Rating', medium: undefined }], + payload: [{ id: 1, name: 'Rating', medium: undefined, description: { json: undefined, html: undefined } }], }, { type: types.ADD_RATINGS_REQUEST, payload: { data: [1], + query: undefined, total: 1, }, }, diff --git a/studio/src/__tests__/actions/roles.js b/studio/src/__tests__/actions/roles.js new file mode 100644 index 000000000..035741cc2 --- /dev/null +++ b/studio/src/__tests__/actions/roles.js @@ -0,0 +1,561 @@ +import axios from 'axios'; +import configureMockStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; + +import * as actions from '../../actions/roles'; +import * as types from '../../constants/roles'; +import { ADD_NOTIFICATION } from '../../constants/notifications'; +import { ADD_MEDIA } from '../../constants/media'; + +const middlewares = [thunk]; +const mockStore = configureMockStore(middlewares); +jest.mock('axios'); +Date.now = jest.fn(() => 1487076708000); + +const initialState = { + req: [], + details: {}, + loading: true, + total: 0, + spaces: { + selected: "new-space" + }, +}; + +describe('roles actions', () => { + it("should create an action to set roles loading to true", () => { + const expectedAction = { + type: types.SET_ROLES_LOADING, + payload: true, + }; + expect(actions.loadingRoles()).toEqual(expectedAction); + }); + + it("should create an action to set roles loading to false", () => { + const expectedAction = { + type: types.SET_ROLES_LOADING, + payload: false, + }; + expect(actions.stopRolesLoading()).toEqual(expectedAction); + }); + + it("should create an action to add roles", () => { + const roles = [ + { + id: 1, + name: "Test Role", + }, + { + id: 2, + name: "Test Role 2", + } + ]; + const expectedAction = { + type: types.ADD_ROLES, + payload: roles, + }; + expect(actions.addRoles(roles)).toEqual(expectedAction); + }); + + it("should create an action to add role request", () => { + const data = [1, 2]; + const query = { + page: 1, + limit: 10, + sort: "name", + order: "asc", + }; + const total = 2; + const expectedAction = { + type: types.ADD_ROLES_REQUEST, + payload: { + data, + query, + total, + }, + }; + expect(actions.addRolesRequest({ data, query, total })).toEqual(expectedAction); + }); + it('should create an action to reset ratings', () => { + const resetRatingsAction = { + type: types.RESET_ROLES, + }; + expect(actions.resetRoles()).toEqual(resetRatingsAction); + }); + + it('should create actions to fetch roles', () => { + const query = { page: 1, limit: 5 }; + const roles = [{ id: 1, name: "Test Role" }]; + const resp = { data: roles }; + axios.get.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: types.ADD_ROLES, + payload: [{ id: 1, name: 'Test Role' }], + }, + { + type: types.ADD_ROLES_REQUEST, + payload: { + data: [1], + query: query, + total: 1, + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.getRoles(query)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.get).toHaveBeenCalledWith(types.ROLES_API(space)); + }); + + it('should create actions to fetch roles with error', () => { + const query = { page: 1, limit: 5 }; + const errorMessage = 'Unable to fetch'; + axios.get.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.getRoles(query)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.get).toHaveBeenCalledWith(types.ROLES_API(space)); + }); + + it('should create actions to fetch role by id failure', () => { + const id = 1; + const errorMessage = 'Unable to fetch'; + axios.get.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.getRole(id)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.get).toHaveBeenCalledWith(types.ROLES_API(space) + '/' + id); + }); + + it('should create actions to fetch role by id', () => { + const id = 1; + const role = { id: 1, name: 'Test Role' }; + const resp = { data: role }; + axios.get.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: types.GET_ROLE, + payload: role, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.getRole(id)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.get).toHaveBeenCalledWith(types.ROLES_API(space) + '/' + id); + }); + + it('should create actions to create role', () => { + const role = { name: 'Test Role' }; + const resp = { data: role }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: types.RESET_ROLES, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Role created', + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.createRole(role)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.post).toHaveBeenCalledWith(types.ROLES_API(space), role); + }); + + it('should create actions to create role with error', () => { + const role = { name: 'Test Role' }; + const errorMessage = 'Unable to create'; + axios.post.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.createRole(role)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.post).toHaveBeenCalledWith(types.ROLES_API(space), role); + }); + + it('should create actions to update role', () => { + const role = { id: 1, name: 'Test Role' }; + const resp = { data: role }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: types.UPDATE_ROLE, + payload: role, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Roles updated', + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + } + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.updateRole(role)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.put).toHaveBeenCalledWith(types.ROLES_API(space) + '/' + role.id, role); + }); + + it('should create actions to update role with error', () => { + const role = { id: 1, name: 'Test Role' }; + const errorMessage = 'Unable to update'; + axios.put.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + } + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.updateRole(role)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.put).toHaveBeenCalledWith(types.ROLES_API(space) + '/' + role.id, role); + }); + + it('should create actions to delete role', () => { + const id = 1; + const resp = { data: id }; + axios.delete.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: types.RESET_ROLES, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Roles deleted', + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + } + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.deleteRole(id)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.delete).toHaveBeenCalledWith(types.ROLES_API(space) + '/' + id); + }); + + it('should create actions to delete role with error', () => { + const id = 1; + const errorMessage = 'Unable to delete'; + axios.delete.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + } + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.deleteRole(id)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.delete).toHaveBeenCalledWith(types.ROLES_API(space) + '/' + id); + }); + + it("should add user to the role successfully", () => { + const role = { id: 1, name: "Test Role" }; + const user = { id: 1, name: "Test User" }; + const resp = { data: role }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: "success", + title: "Success", + message: "User Added Succesfully", + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.addRoleUser(role.id, user)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.post).toHaveBeenCalledWith(types.ROLES_API(space) + "/" + role.id + "/users", user); + }); + + it("should add user to the role with error", () => { + const role = { id: 1, name: "Test Role" }; + const user = { id: 1, name: "Test User" }; + const errorMessage = "Unable to add user"; + axios.post.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: "error", + title: "Error", + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.addRoleUser(role.id, user)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.post).toHaveBeenCalledWith(types.ROLES_API(space) + "/" + role.id + "/users", user); + }); + + it("should remove user from the role successfully", () => { + const role = { id: 1, name: "Test Role", users: [{ id: 1, name: "Test User" }] }; + + const resp = { data: role }; + axios.delete.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: "success", + title: "Success", + message: "User Removed Succesfully", + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.removeRoleUser(role.id, role.users[0])) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.delete).toHaveBeenCalledWith(types.ROLES_API(space) + "/" + role.id + "/users/" + role.users[0].id); + }); + + it("should remove user from the role with error", () => { + const role = { id: 1, name: "Test Role", users: [{ id: 1, name: "Test User" }] }; + const errorMessage = "Unable to remove user"; + axios.delete.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_ROLES_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: "error", + title: "Error", + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_ROLES_LOADING, + payload: false, + }, + ]; + + const store = mockStore(initialState); + store + .dispatch(actions.removeRoleUser(role.id, role.users[0])) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + const space = store.getState().spaces.selected; + expect(axios.delete).toHaveBeenCalledWith(types.ROLES_API(space) + "/" + role.id + "/users/" + role.users[0].id); + }); +}); + diff --git a/studio/src/actions/categories.js b/studio/src/actions/categories.js index 272f4af17..47e4aea86 100644 --- a/studio/src/actions/categories.js +++ b/studio/src/actions/categories.js @@ -105,10 +105,10 @@ export const updateCategory = (data) => { .put(CATEGORIES_API + '/' + data.id, data) .then((response) => { if (response.data.medium) dispatch(addMedia([response.data.medium])); - response.data.description = { - json: response.data.description, - html: response.data.description_html, - }; + // response.data.description = { + // json: response.data.description, + // html: response.data.description_html, + // }; dispatch( addCategory(UPDATE_CATEGORY, { ...response.data, medium: response.data.medium?.id }), ); @@ -145,10 +145,11 @@ export const addCategories = (categories) => { dispatch( addCategoriesList( categories.map((category) => { - category.description = { + category.description = typeof category.description === 'object' && category.description.hasOwnProperty('json') && category.description.hasOwnProperty('html') ? category.description : { json: category.description, html: category.description_html, }; + category.description_html && delete category.description_html; return { ...category, medium: category.medium?.id }; }), ), diff --git a/studio/src/actions/claimants.js b/studio/src/actions/claimants.js index ba5b33409..0f1ffb2b7 100644 --- a/studio/src/actions/claimants.js +++ b/studio/src/actions/claimants.js @@ -44,7 +44,7 @@ export const getClaimants = (query) => { // ! description_html: ... // ! } //! possible solution is to delete the description_html - // delete claimant.description_html; + delete claimant.description_html; return { ...claimant, medium: claimant.medium?.id }; }), ), diff --git a/studio/src/actions/pages.js b/studio/src/actions/pages.js index 02248dac2..4880c3436 100644 --- a/studio/src/actions/pages.js +++ b/studio/src/actions/pages.js @@ -104,6 +104,8 @@ export const getPages = (query) => { addPagesList( response.data.nodes.map((page) => { page.description = { json: page.description, html: page.description_html }; + // ! delete description_html + delete page.description_html; return { ...page, medium: page.medium?.id, @@ -138,6 +140,8 @@ export const getPage = (id) => { .then((response) => { let page = response.data; page.description = { json: page.description, html: page.description_html }; + // ! delete description_html + delete page.description_html; dispatch(addTags(page.tags)); dispatch(addAuthors(page.authors)); dispatch(addCategories(page.categories)); @@ -168,6 +172,8 @@ export const addPage = (data) => { .then((response) => { let page = response.data; page.description = { json: page.description, html: page.description_html }; + // ! delete description_html + delete page.description_html; dispatch(addTags(page.tags)); dispatch(addCategories(page.categories)); dispatch(addAuthors(page.authors)); @@ -194,7 +200,9 @@ export const updatePage = (data) => { .put(PAGES_API + '/' + data.id, data) .then((response) => { let page = response.data; - page.description = { json: page.description, html: page.description_html }; + // ! not needed + // page.description = { json: page.description, html: page.description_html }; + // delete page.description_html; dispatch(addTags(page.tags)); dispatch(addCategories(page.categories)); dispatch(addAuthors(page.authors)); diff --git a/studio/src/actions/ratings.js b/studio/src/actions/ratings.js index a47d87de5..8422108a0 100644 --- a/studio/src/actions/ratings.js +++ b/studio/src/actions/ratings.js @@ -23,6 +23,8 @@ export const addDefaultRatings = (query) => { addRatingsList( response.data.nodes.map((rating) => { rating.description = { json: rating.description, html: rating.description_html }; + // !delete rating.description_html; + delete rating.description_html; return { ...rating, medium: rating.medium?.id }; }), ), @@ -60,6 +62,8 @@ export const getRatings = (query) => { addRatingsList( response.data.nodes.map((rating) => { rating.description = { json: rating.description, html: rating.description_html }; + // !delete rating.description_html; + delete rating.description_html; return { ...rating, medium: rating.medium?.id }; }), ), @@ -91,6 +95,8 @@ export const getRating = (id) => { json: response.data.description, html: response.data.description_html, }; + // !delete response.data.description_html; + delete response.data.description_html; dispatch(addRating(GET_RATING, { ...response.data, medium: response.data.medium?.id })); }) .catch((error) => { @@ -125,7 +131,10 @@ export const updateRating = (data) => { .then((response) => { const rating = response.data; if (rating.medium) dispatch(addMedia([rating.medium])); - rating.description = { json: rating.description, html: rating.description_html }; + if (typeof rating.description === "string" || rating.description === undefined) { + rating.description = { json: rating.description, html: rating.description_html }; + delete rating.description_html; + } dispatch(addRating(UPDATE_RATING, { ...rating, medium: rating.medium?.id })); dispatch(addSuccessNotification('Rating updated')); }) @@ -157,6 +166,9 @@ export const addRatings = (ratings) => { dispatch( addRatingsList( ratings.map((rating) => { + rating.description = { json: rating.description, html: rating.description_html }; + // !delete rating.description_html; + delete rating.description_html; return { ...rating, medium: rating.medium?.id }; }), ), diff --git a/studio/src/actions/roles.js b/studio/src/actions/roles.js index 3b8c9e4f6..73746b1d0 100644 --- a/studio/src/actions/roles.js +++ b/studio/src/actions/roles.js @@ -22,9 +22,11 @@ export const getRoles = (query) => { dispatch(addRoles(response.data)); dispatch( addRolesRequest({ + //! HERE EITHER WE HAVE TO USE MAP OVER data.nodes data: response.data.map((item) => item.id), query: query, - total: response.data.total, + //! or we have to change the response.data.total to response.data.length + total: response.data.length, }), ); }) @@ -65,7 +67,9 @@ export const createRole = (data) => { }) .catch((error) => { dispatch(addErrorNotification(getError(error))); - }); + }) + //! HERE WE HAVE TO STOP LOADING AFTER CREATING ROLE + .finally(() => dispatch(stopRolesLoading())); }; }; From 2c5fbf21174ab18edfb43973fad2e7359c832759 Mon Sep 17 00:00:00 2001 From: Ishpaul Singhhello
" }, + rating: { id: 100, name: 'Rating 1', medium: { id: 110, name: 'Medium-Rating 1' } }, }; const local_claim2 = { id: 2, name: 'Claim 2', claimant: { id: 12, name: 'Claimant 2', medium: { id: 22, name: 'Medium-Claimant 2' } }, - rating: { id: 200, name: 'Rating 2', medium: { id: 220, name: 'Medium-Rating 2' } }, + rating: { id: 200, name: 'Rating 2', medium: { id: 220, name: 'Medium-Rating 2' }, description: { "hello": "test" }, description_html: "hello
" }, }; const claims = [local_claim1, local_claim2] @@ -698,8 +718,18 @@ describe('claims actions', () => { { type: ADD_CLAIMANTS, payload: [ - { id: 11, name: 'Claimant 1', medium: 21 }, - { id: 12, name: 'Claimant 2', medium: 22 }, + { + id: 11, name: 'Claimant 1', medium: 21, + description: { + json: { "hello": "test" }, html: "hello
" + } + }, + { + id: 12, name: 'Claimant 2', medium: 22, + description: { + json: undefined, html: undefined + } + }, ], }, { @@ -712,8 +742,14 @@ describe('claims actions', () => { { type: ADD_RATINGS, payload: [ - { id: 100, name: 'Rating 1', medium: 110 }, - { id: 200, name: 'Rating 2', medium: 220 }, + { + id: 100, name: 'Rating 1', medium: 110, + description: { json: undefined, html: undefined } + }, + { + id: 200, name: 'Rating 2', medium: 220, + description: { json: { "hello": "test" }, html: "hello
" } + }, ], }, { diff --git a/studio/src/__tests__/actions/podcasts.js b/studio/src/__tests__/actions/podcasts.js index 37123ff99..02e3b7b96 100644 --- a/studio/src/__tests__/actions/podcasts.js +++ b/studio/src/__tests__/actions/podcasts.js @@ -80,6 +80,8 @@ describe('Podcast actions', () => { title: 'Podcast', episodes: [{ id: 1 }], categories: [{ id: 1, medium: { id: 1 } }], + description: { "hello": "world" }, + description_html: "hello world
" }, ]; const resp = { data: { nodes: podcasts, total: 1 } }; @@ -96,11 +98,16 @@ describe('Podcast actions', () => { }, { type: ADD_CATEGORIES, - payload: [{ id: 1, medium: 1 }], + payload: [{ + id: 1, medium: 1, description: { + json: undefined, + html: undefined, + } + }], }, { type: types.ADD_PODCASTS, - payload: [{ id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1] }], + payload: [{ id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1], description: { json: { "hello": "world" }, html: "hello world
" } }], }, { type: types.ADD_PODCASTS_REQUEST, @@ -121,6 +128,7 @@ describe('Podcast actions', () => { .dispatch(actions.getPodcasts(query)) .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.get).toHaveBeenCalledTimes(1); + }); it('should create actions to fetch podcasts failure', () => { const query = { page: 1, limit: 5 }; @@ -161,7 +169,9 @@ describe('Podcast actions', () => { id, title: 'Podcast', episodes: [{ id: 1 }], - categories: [{ id: 1, medium: { id: 1 } }], + categories: [{ id: 1, medium: { id: 1 }, description: { "hello": "world" }, description_html: "hello world
" }], + description: { "hello": "world" }, + description_html: "hello world
" }; const resp = { data: podcast }; axios.get.mockResolvedValue(resp); @@ -177,7 +187,7 @@ describe('Podcast actions', () => { }, { type: ADD_CATEGORIES, - payload: [{ id: 1, medium: 1 }], + payload: [{ id: 1, medium: 1, description: { json: { "hello": "world" }, html: "hello world
" } }], }, { type: types.ADD_PODCAST, @@ -186,6 +196,7 @@ describe('Podcast actions', () => { title: 'Podcast', episodes: [{ id: 1 }], categories: [1], + description: { json: { "hello": "world" }, html: "hello world
" } }, }, { @@ -293,7 +304,8 @@ describe('Podcast actions', () => { id: 1, title: 'Podcast', episodes: [{ id: 1 }], - categories: [{ id: 1, medium: { id: 1 } }], + categories: [{ id: 1, medium: { id: 1 }, description: { "hello": "world" }, description_html: "hello world
" }], + description: { json: { "hello": "world" }, html: "hello world
" } }; const resp = { data: podcast }; axios.put.mockResolvedValue(resp); @@ -309,11 +321,12 @@ describe('Podcast actions', () => { }, { type: ADD_CATEGORIES, - payload: [{ id: 1, medium: 1 }], + payload: [{ id: 1, medium: 1, description: { json: { "hello": "world" }, html: "hello world
" } }], }, { type: types.ADD_PODCAST, - payload: { id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1] }, + payload: { id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1], + description: { json: { "hello": "world" }, html: "hello world
" } }, }, { type: ADD_NOTIFICATION, diff --git a/studio/src/__tests__/actions/roles.js b/studio/src/__tests__/actions/roles.js index 035741cc2..1fa6ec430 100644 --- a/studio/src/__tests__/actions/roles.js +++ b/studio/src/__tests__/actions/roles.js @@ -507,7 +507,7 @@ describe('roles actions', () => { payload: { type: "success", title: "Success", - message: "User Removed Succesfully", + message: "User Deleted Succesfully", time: Date.now(), }, }, @@ -519,7 +519,7 @@ describe('roles actions', () => { const store = mockStore(initialState); store - .dispatch(actions.removeRoleUser(role.id, role.users[0])) + .dispatch(actions.deleteRoleUser(role.id, role.users[0].id)) .then(() => expect(store.getActions()).toEqual(expectedActions)); const space = store.getState().spaces.selected; expect(axios.delete).toHaveBeenCalledWith(types.ROLES_API(space) + "/" + role.id + "/users/" + role.users[0].id); @@ -552,7 +552,7 @@ describe('roles actions', () => { const store = mockStore(initialState); store - .dispatch(actions.removeRoleUser(role.id, role.users[0])) + .dispatch(actions.deleteRoleUser(role.id, role.users[0].id)) .then(() => expect(store.getActions()).toEqual(expectedActions)); const space = store.getState().spaces.selected; expect(axios.delete).toHaveBeenCalledWith(types.ROLES_API(space) + "/" + role.id + "/users/" + role.users[0].id); diff --git a/studio/src/actions/claimants.js b/studio/src/actions/claimants.js index 0f1ffb2b7..d1c806d8c 100644 --- a/studio/src/actions/claimants.js +++ b/studio/src/actions/claimants.js @@ -154,6 +154,9 @@ export const addClaimants = (claimants) => { //! description: ... //! description_html: ... //! } + claimant.description = { json: claimant.description, html: claimant.description_html }; + delete claimant.description_html; + //! whereas above they are copied inside single object = { //! ... //! description: { diff --git a/studio/src/actions/podcasts.js b/studio/src/actions/podcasts.js index dd7fe5cc2..ab2627db5 100644 --- a/studio/src/actions/podcasts.js +++ b/studio/src/actions/podcasts.js @@ -51,7 +51,10 @@ export const getPodcasts = (query) => { dispatch( addPodcastsList( response.data.nodes.map((podcast) => { - podcast = { json: podcast.description, html: podcast.description_html }; + // !here podast.description should be modified not podcast + // podcast = { json: podcast.description, html: podcast.description_html }; + podcast.description = { json: podcast.description, html: podcast.description_html }; + delete podcast.description_html; return { ...podcast, categories: podcast.categories?.map((category) => category.id), @@ -81,7 +84,10 @@ export const getPodcast = (id) => { .get(PODCASTS_API + '/' + id) .then((response) => { let podcast = response.data; - podcast = { json: podcast.description, html: podcast.description_html }; + // !here podast.description should be modified not podcast + // podcast = { json: podcast.description, html: podcast.description_html }; + podcast.description = { json: podcast.description, html: podcast.description_html }; + delete podcast.description_html; dispatch(addCategories(podcast.categories)); dispatch( getPodcastByID({ @@ -119,7 +125,8 @@ export const updatePodcast = (data) => { .put(PODCASTS_API + '/' + data.id, data) .then((response) => { let podcast = response.data; - podcast = { json: podcast.description, html: podcast.description_html }; + // !here podast.description should not be modified neither podcast + // podcast = { json: podcast.description, html: podcast.description_html }; dispatch(addCategories(podcast.categories)); dispatch( getPodcastByID({ From 6eb975661e231d4add23baf68be9e6d9f2f758e8 Mon Sep 17 00:00:00 2001 From: Ishpaul Singhhello
" }, ], format: { id: 41, name: 'Format 1' }, medium: { id: 51, name: 'Medium 1' }, @@ -91,6 +91,8 @@ const post_without_media = { }, ], }; + + describe('posts actions', () => { it('should create an action to set loading to true', () => { const startLoadingAction = { @@ -107,7 +109,7 @@ describe('posts actions', () => { expect(actions.stopPostsLoading()).toEqual(stopLoadingAction); }); it('should create an action to add posts list', () => { - const data = [post, post2]; + const data = [Object.create(post), Object.create(post2)]; const addPostsAction = { type: types.ADD_POSTS, @@ -149,7 +151,8 @@ describe('posts actions', () => { status: 'draft', author: [11], }; - const posts = [{ ...post, status: 'draft' }]; + let post1 = { ...post, description: { "hello": "test" }, description_html: "hello
" }; + const posts = [{ ...post1, status: 'draft' }]; const resp = { data: { nodes: posts, total: 1 } }; axios.get.mockResolvedValue(resp); @@ -176,8 +179,19 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + }, + }, + { + id: 32, name: 'category 32', medium: undefined, description: { + json: { "hello": "test" }, + html: 'hello
', + } + }, ], }, { @@ -190,7 +204,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + }, + }], }, { type: ADD_MEDIA, @@ -198,7 +217,7 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ id: 602, name: 'Rating 1', medium: 622, description: { json: undefined, html: undefined } }], }, { type: ADD_CLAIMS, @@ -216,6 +235,10 @@ describe('posts actions', () => { name: 'Post 1', status: 'draft', authors: [11], + description: { + json: { "hello": "test" }, + html: 'hello
', + }, tags: [21, 22], categories: [31, 32], format: 41, @@ -259,7 +282,30 @@ describe('posts actions', () => { format: [42], status: 'publish', }; - const posts = [{ ...post, status: 'publish' }]; + const post_without_id_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + }; + let post1 = { ...post_without_id_local, id: 1, description: { "hello": "test" }, description_html: "hello
" }; + const posts = [{ ...post1, status: 'publish' }]; const resp = { data: { nodes: posts, total: 1 } }; axios.get.mockResolvedValue(resp); @@ -286,8 +332,19 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + }, + }, + { + id: 32, name: 'category 32', medium: undefined, description: { + json: { "hello": "test" }, + html: 'hello
', + } + }, ], }, { @@ -300,7 +357,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + }, + }], }, { type: ADD_MEDIA, @@ -308,7 +370,7 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ id: 602, name: 'Rating 1', medium: 622, description: { json: undefined, html: undefined } }], }, { type: ADD_CLAIMS, @@ -326,6 +388,10 @@ describe('posts actions', () => { name: 'Post 1', status: 'publish', authors: [11], + description: { + json: { "hello": "test" }, + html: 'hello
', + }, tags: [21, 22], categories: [31, 32], format: 41, @@ -433,6 +499,10 @@ describe('posts actions', () => { categories: [], format: 41, medium: undefined, + description: { + json: undefined, + html: undefined, + }, claims: [], }, ], @@ -512,7 +582,33 @@ describe('posts actions', () => { }); it('should create actions to get post by id success', () => { const id = 1; - const resp = { data: post }; + const post_local = { + id: 1, + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' }, }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + description: { "hello": "test" }, + description_html: "hello
", + }; + + const resp = { data: post_local }; axios.get.mockResolvedValue(resp); const expectedActions = [ @@ -538,8 +634,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -548,7 +656,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -556,11 +669,18 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, - payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + payload: [{ + id: 61, name: 'Claim 1', claimant: 601, rating: 602, + }], }, { type: ADD_FORMATS, @@ -581,6 +701,10 @@ describe('posts actions', () => { format: 41, medium: 51, claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } }, }, { @@ -663,6 +787,10 @@ describe('posts actions', () => { format: 41, medium: undefined, claims: [], + description: { + json: undefined, + html: undefined, + } }, }, { @@ -721,7 +849,31 @@ describe('posts actions', () => { expect(axios.get).toHaveBeenCalledWith(types.POSTS_API + '/' + id); }); it('should create actions to create post success', () => { - const data2 = { ...post }; + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + }; + + const data2 = Object.create(post_local); data2.status = 'publish'; const resp = { data: data2 }; axios.post.mockResolvedValue(resp); @@ -745,8 +897,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -759,7 +923,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -767,7 +936,12 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, @@ -917,7 +1091,35 @@ describe('posts actions', () => { expect(axios.post).toHaveBeenCalledWith(types.POSTS_API, post); }); it('should create actions to update post success', () => { - const data2 = { ...post }; + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }; + + const data2 = { ...post_local }; data2.status = 'draft'; const resp = { data: data2 }; axios.put.mockResolvedValue(resp); @@ -941,8 +1143,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -955,7 +1169,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -963,7 +1182,12 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, @@ -989,6 +1213,10 @@ describe('posts actions', () => { format: 41, medium: 51, claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } }, }, { @@ -1013,7 +1241,35 @@ describe('posts actions', () => { expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', data2); }); it('should create actions to publish post success', () => { - const resp = { data: post }; + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }; + + const resp = { data: post_local }; axios.put.mockResolvedValue(resp); const expectedActions = [ @@ -1035,8 +1291,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -1049,7 +1317,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -1057,7 +1330,12 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, @@ -1082,6 +1360,10 @@ describe('posts actions', () => { format: 41, medium: 51, claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } }, }, { @@ -1106,11 +1388,34 @@ describe('posts actions', () => { expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); }); it('should create actions to publish post success without medium', () => { - const resp = { data: post_without_media }; + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + }; + + const resp = { data: post_local }; axios.put.mockResolvedValue(resp); const expectedActions = [ - { + { type: types.SET_POSTS_LOADING, payload: true, }, @@ -1128,8 +1433,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -1142,7 +1459,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -1150,7 +1472,12 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, @@ -1163,13 +1490,18 @@ describe('posts actions', () => { { type: types.ADD_POST, payload: { - id: 123, + id: 1, name: 'Post 1', authors: [11], tags: [21, 22], categories: [31, 32], format: 41, + medium: undefined, claims: [61], + description: { + json: undefined, + html: undefined, + } }, }, { @@ -1197,7 +1529,35 @@ describe('posts actions', () => { ); }); it('should create actions to publish success', () => { - const resp = { data: post }; + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }; + + const resp = { data: post_local }; axios.post.mockResolvedValue(resp); const expectedActions = [ @@ -1219,8 +1579,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -1233,7 +1605,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -1241,7 +1618,12 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, @@ -1266,94 +1648,10 @@ describe('posts actions', () => { format: 41, medium: 51, claims: [61], - }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Post published', - time: Date.now(), - }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; - - const store = mockStore({ initialState }); - store - .dispatch(actions.publish(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post); - }); - it('should create actions to publish success without medium', () => { - const resp = { data: post_without_media }; - axios.post.mockResolvedValue(resp); - - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [ - { id: 21, name: 'Tag 21' }, - { id: 22, name: 'Tag 22' }, - ], - }, - { - type: ADD_MEDIA, - payload: [{ id: 311, name: 'Category-Medium-311' }], - }, - { - type: ADD_CATEGORIES, - payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, - ], - }, - { - type: ADD_AUTHORS, - payload: [{ id: 11, name: 'Author 1' }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 621, name: 'Medium-Claimant 1' }], - }, - { - type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 622, name: 'Medium-Rating 1' }], - }, - { - type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], - }, - { - type: ADD_CLAIMS, - payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], - }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], - }, - { - type: types.ADD_POST, - payload: { - id: 123, - name: 'Post 1', - authors: [11], - tags: [21, 22], - categories: [31, 32], - format: 41, - claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } }, }, { @@ -1410,7 +1708,34 @@ describe('posts actions', () => { }); it('should create actions to template success', () => { - const resp = { data: post }; + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }; + const resp = { data: post_local }; axios.post.mockResolvedValue(resp); const expectedActions = [ @@ -1432,8 +1757,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -1446,7 +1783,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -1454,7 +1796,12 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, @@ -1479,6 +1826,10 @@ describe('posts actions', () => { format: 41, medium: 51, claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } }, }, { @@ -1504,7 +1855,30 @@ describe('posts actions', () => { }); it('should create actions to template success without medium', () => { - const resp = { data: post_without_media }; + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + }; + + const resp = { data: post_local }; axios.post.mockResolvedValue(resp); const expectedActions = [ @@ -1526,8 +1900,20 @@ describe('posts actions', () => { { type: ADD_CATEGORIES, payload: [ - { id: 31, name: 'category 31', medium: 311 }, - { id: 32, name: 'category 32', medium: undefined }, + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, ], }, { @@ -1540,7 +1926,12 @@ describe('posts actions', () => { }, { type: ADD_CLAIMANTS, - payload: [{ id: 601, name: 'Claimant 1', medium: 621 }], + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_MEDIA, @@ -1548,7 +1939,12 @@ describe('posts actions', () => { }, { type: ADD_RATINGS, - payload: [{ id: 602, name: 'Rating 1', medium: 622 }], + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], }, { type: ADD_CLAIMS, @@ -1561,13 +1957,18 @@ describe('posts actions', () => { { type: types.ADD_POST, payload: { - id: 123, + id: 1, name: 'Post 1', authors: [11], tags: [21, 22], categories: [31, 32], format: 41, + medium: undefined, claims: [61], + description: { + json: undefined, + html: undefined, + } }, }, { @@ -1587,9 +1988,9 @@ describe('posts actions', () => { const store = mockStore({ initialState }); store - .dispatch(actions.addTemplate(post_without_media)) + .dispatch(actions.addTemplate(post_local)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post_without_media); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post_local); }); it('should create actions to template failure', () => { @@ -1692,6 +2093,10 @@ describe('posts actions', () => { medium: undefined, claims: [], status: 'publish', + description: { + json: undefined, + html: undefined, + } }, }, { @@ -1784,6 +2189,10 @@ describe('posts actions', () => { medium: undefined, claims: [], status: 'ready', + description: { + json: undefined, + html: undefined, + } }, }, { diff --git a/studio/src/actions/posts.js b/studio/src/actions/posts.js index 6c75f3d1c..3aecd4ecb 100644 --- a/studio/src/actions/posts.js +++ b/studio/src/actions/posts.js @@ -120,6 +120,8 @@ export const getPosts = (query) => { addPostsList( response.data.nodes.map((post) => { post.description = { json: post.description, html: post.description_html }; + // need to delete the html description from the post object + delete post.description_html; return { ...post, categories: post.categories.map((category) => category.id), @@ -155,6 +157,8 @@ export const getPost = (id) => { .then((response) => { let post = response.data; post.description = { json: post.description, html: post.description_html }; + // need to delete the html description from the post object + delete post.description_html; dispatch(addTags(post.tags)); dispatch(addAuthors(post.authors)); dispatch(addCategories(post.categories)); @@ -200,8 +204,8 @@ export const addPost = (data) => { post.status === 'publish' ? dispatch(addSuccessNotification(`${post.format.name} Published`)) : post.status === 'draft' - ? dispatch(addSuccessNotification('Post added')) - : dispatch(addSuccessNotification('Post added & Ready to Publish')); + ? dispatch(addSuccessNotification('Post added')) + : dispatch(addSuccessNotification('Post added & Ready to Publish')); return post; }) .catch((error) => { @@ -217,7 +221,10 @@ export const publish = (data) => { .post(POSTS_API + '/publish', data) .then((response) => { let post = response.data; - post.description = { json: post.description, html: post.description_html }; + if (typeof post.description !== 'object') { + post.description = { json: post.description, html: post.description_html }; + delete post.description_html; + } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); dispatch(addAuthors(post.authors)); @@ -252,7 +259,10 @@ export const addTemplate = (data) => { .post(POSTS_API + '/templates', data) .then((response) => { let post = response.data; - post.description = { json: post.description, html: post.description_html }; + if (typeof post.description !== 'object') { + post.description = { json: post.description, html: post.description_html }; + delete post.description_html; + } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); dispatch(addAuthors(post.authors || [])); @@ -287,7 +297,10 @@ export const publishPost = (data) => { .put(POSTS_API + '/' + data.id + '/publish', data) .then((response) => { let post = response.data; - post.description = { json: post.description, html: post.description_html }; + if (typeof post.description !== 'object') { + post.description = { json: post.description, html: post.description_html }; + delete post.description_html; + } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); dispatch(addAuthors(post.authors)); @@ -322,7 +335,10 @@ export const updatePost = (data) => { .put(POSTS_API + '/' + data.id, data) .then((response) => { let post = response.data; - post.description = { json: post.description, html: post.description_html }; + if (typeof post.description !== 'object') { + post.description = { json: post.description, html: post.description_html }; + delete post.description_html; + } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); dispatch(addAuthors(post.authors)); @@ -344,8 +360,8 @@ export const updatePost = (data) => { data.status === 'publish' ? dispatch(addSuccessNotification(`${post.format.name} Published`)) : data.status === 'draft' - ? dispatch(addSuccessNotification('Draft Saved')) - : dispatch(addSuccessNotification('Draft saved & Ready to Publish')); + ? dispatch(addSuccessNotification('Draft Saved')) + : dispatch(addSuccessNotification('Draft saved & Ready to Publish')); }) .catch((error) => { dispatch(addErrorNotification(getError(error))); From 36afb8caa6bf2e94b3e5d964f29cfa8b15061a43 Mon Sep 17 00:00:00 2001 From: Ishpaul Singhhello
", - } + description: { "hello": "test" }, + description_html: "hello
" }; + const resp = { data: post_local }; axios.post.mockResolvedValue(resp); @@ -1837,7 +1815,7 @@ describe('posts actions', () => { payload: { type: 'success', title: 'Success', - message: 'Template created', + message: 'Post published', time: Date.now(), }, }, @@ -1847,499 +1825,678 @@ describe('posts actions', () => { }, ]; - const store = mockStore({ initialState }); + const store = mockStore({initialState}); store - .dispatch(actions.addTemplate(post)) + .dispatch(actions.publish(post_local)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); - }); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post_local); +}); - it('should create actions to template success without medium', () => { - const post_local = { - name: 'Post 1', - authors: [{ id: 11, name: 'Author 1' }], - tags: [ + +it('should create actions to publish failure', () => { + const errorMessage = 'Failed to publish post'; + axios.post.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.publish(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post); +}); + +it('should create actions to template success', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }; + const resp = { data: post_local }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ { id: 21, name: 'Tag 21' }, { id: 22, name: 'Tag 22' }, ], - categories: [ - { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, - { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, - ], - format: { id: 41, name: 'Format 1' }, - claims: [ + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ { - id: 61, - name: 'Claim 1', - claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, - rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, - }, - ], - id: 1, - }; - - const resp = { data: post_local }; - axios.post.mockResolvedValue(resp); - - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [ - { id: 21, name: 'Tag 21' }, - { id: 22, name: 'Tag 22' }, - ], - }, - { - type: ADD_MEDIA, - payload: [{ id: 311, name: 'Category-Medium-311' }], - }, - { - type: ADD_CATEGORIES, - payload: [ - { - id: 31, name: 'category 31', medium: 311, - description: { - json: undefined, - html: undefined, - } - }, - { - id: 32, name: 'category 32', medium: undefined, - description: { - json: { "hello": "test" }, - html: "hello
", - } - }, - ], - }, - { - type: ADD_AUTHORS, - payload: [{ id: 11, name: 'Author 1' }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 621, name: 'Medium-Claimant 1' }], - }, - { - type: ADD_CLAIMANTS, - payload: [{ - id: 601, name: 'Claimant 1', medium: 621, description: { + id: 31, name: 'category 31', medium: 311, + description: { json: undefined, html: undefined, } - }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 622, name: 'Medium-Rating 1' }], - }, - { - type: ADD_RATINGS, - payload: [{ - id: 602, name: 'Rating 1', medium: 622, description: { - json: undefined, - html: undefined, + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", } - }], - }, - { - type: ADD_CLAIMS, - payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: 51, + claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Template created', + time: Date.now(), }, - { - type: types.ADD_POST, - payload: { - id: 1, - name: 'Post 1', - authors: [11], - tags: [21, 22], - categories: [31, 32], - format: 41, - medium: undefined, - claims: [61], + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.addTemplate(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); +}); + +it('should create actions to template success without medium', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + }; + + const resp = { data: post_local }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { + id: 31, name: 'category 31', medium: 311, description: { json: undefined, html: undefined, } }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Template created', - time: Date.now(), + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: undefined, + claims: [61], + description: { + json: undefined, + html: undefined, + } }, - { - type: types.SET_POSTS_LOADING, - payload: false, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Template created', + time: Date.now(), }, - ]; + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.addTemplate(post_local)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post_local); - }); + const store = mockStore({ initialState }); + store + .dispatch(actions.addTemplate(post_local)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post_local); +}); - it('should create actions to template failure', () => { - const errorMessage = 'Failed to publish post'; - axios.post.mockRejectedValue(new Error(errorMessage)); +it('should create actions to template failure', () => { + const errorMessage = 'Failed to publish post'; + axios.post.mockRejectedValue(new Error(errorMessage)); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), - }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), }, - ]; + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.addTemplate(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); - }); + const store = mockStore({ initialState }); + store + .dispatch(actions.addTemplate(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); +}); - it('should create actions to update success without any optional fields', () => { - const post_without_fields = { ...post }; - post_without_fields.categories = []; - post_without_fields.authors = []; - post_without_fields.tags = []; - post_without_fields.claims = []; - post_without_fields.medium = undefined; - post_without_fields.status = 'publish'; +it('should create actions to update success without any optional fields', () => { + const post_without_fields = { ...post }; + post_without_fields.categories = []; + post_without_fields.authors = []; + post_without_fields.tags = []; + post_without_fields.claims = []; + post_without_fields.medium = undefined; + post_without_fields.status = 'publish'; - const resp = { data: post_without_fields }; - axios.put.mockResolvedValue(resp); + const resp = { data: post_without_fields }; + axios.put.mockResolvedValue(resp); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CATEGORIES, - payload: [], - }, - { - type: ADD_AUTHORS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CLAIMANTS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_RATINGS, - payload: [], - }, - { - type: ADD_CLAIMS, - payload: [], - }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], - }, - { - type: types.ADD_POST, - payload: { - id: 1, - name: 'Post 1', - authors: [], - tags: [], - categories: [], - format: 41, - medium: undefined, - claims: [], - status: 'publish', - description: { - json: undefined, - html: undefined, - } - }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Format 1 Published', - time: Date.now(), - }, + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_CATEGORIES, + payload: [], + }, + { + type: ADD_AUTHORS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_CLAIMANTS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_RATINGS, + payload: [], + }, + { + type: ADD_CLAIMS, + payload: [], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [], + tags: [], + categories: [], + format: 41, + medium: undefined, + claims: [], + status: 'publish', + description: { + json: undefined, + html: undefined, + } }, - { - type: types.SET_POSTS_LOADING, - payload: false, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Format 1 Published', + time: Date.now(), }, - ]; - - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post_without_fields)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); - }); - it('should create actions to update success without any optional fields with ready status', () => { - const post_without_fields = { ...post }; - post_without_fields.categories = []; - post_without_fields.authors = []; - post_without_fields.tags = []; - post_without_fields.claims = []; - post_without_fields.medium = undefined; - post_without_fields.status = 'ready'; - - const resp = { data: post_without_fields }; - axios.put.mockResolvedValue(resp); + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CATEGORIES, - payload: [], - }, - { - type: ADD_AUTHORS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CLAIMANTS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_RATINGS, - payload: [], - }, - { - type: ADD_CLAIMS, - payload: [], - }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], - }, - { - type: types.ADD_POST, - payload: { - id: 1, - name: 'Post 1', - authors: [], - tags: [], - categories: [], - format: 41, - medium: undefined, - claims: [], - status: 'ready', - description: { - json: undefined, - html: undefined, - } - }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Draft saved & Ready to Publish', - time: Date.now(), - }, + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post_without_fields)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); +}); +it('should create actions to update success without any optional fields with ready status', () => { + const post_without_fields = { ...post }; + post_without_fields.categories = []; + post_without_fields.authors = []; + post_without_fields.tags = []; + post_without_fields.claims = []; + post_without_fields.medium = undefined; + post_without_fields.status = 'ready'; + + const resp = { data: post_without_fields }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_CATEGORIES, + payload: [], + }, + { + type: ADD_AUTHORS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_CLAIMANTS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_RATINGS, + payload: [], + }, + { + type: ADD_CLAIMS, + payload: [], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [], + tags: [], + categories: [], + format: 41, + medium: undefined, + claims: [], + status: 'ready', + description: { + json: undefined, + html: undefined, + } }, - { - type: types.SET_POSTS_LOADING, - payload: false, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Draft saved & Ready to Publish', + time: Date.now(), }, - ]; + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post_without_fields)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); - }); - it('should throw error on update post without required field format', () => { - const { format, ...post_without_format } = post; + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post_without_fields)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); +}); +it('should throw error on update post without required field format', () => { + const { format, ...post_without_format } = post; - const resp = { data: post_without_format }; - axios.put.mockResolvedValue(resp); + const resp = { data: post_without_format }; + axios.put.mockResolvedValue(resp); - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post_without_format)) - .catch((err) => expect(err).toBeInstanceOf(TypeError)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_format); - }); - it('should create actions to update post failure', () => { - const errorMessage = 'Failed to update post'; - axios.put.mockRejectedValue(new Error(errorMessage)); + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post_without_format)) + .catch((err) => expect(err).toBeInstanceOf(TypeError)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_format); +}); +it('should create actions to update post failure', () => { + const errorMessage = 'Failed to update post'; + axios.put.mockRejectedValue(new Error(errorMessage)); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), - }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), }, - ]; + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post); - }); - it('should create actions to publish post failure', () => { - const errorMessage = 'Failed to publish post'; - axios.put.mockRejectedValue(new Error(errorMessage)); + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post); +}); +it('should create actions to publish post failure', () => { + const errorMessage = 'Failed to publish post'; + axios.put.mockRejectedValue(new Error(errorMessage)); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), - }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), }, - ]; + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.publishPost(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); - }); - it('should create actions to delete post success', () => { - axios.delete.mockResolvedValue(); + const store = mockStore({ initialState }); + store + .dispatch(actions.publishPost(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); +}); +it('should create actions to delete post success', () => { + axios.delete.mockResolvedValue(); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: types.RESET_POSTS, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Post deleted', - time: Date.now(), - }, + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: types.RESET_POSTS, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Post deleted', + time: Date.now(), }, - ]; + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.deletePost(1)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); - }); - it('should create actions to delete post failure', () => { - const errorMessage = 'Failed to delete post'; - axios.delete.mockRejectedValue(new Error(errorMessage)); + const store = mockStore({ initialState }); + store + .dispatch(actions.deletePost(1)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); +}); +it('should create actions to delete post failure', () => { + const errorMessage = 'Failed to delete post'; + axios.delete.mockRejectedValue(new Error(errorMessage)); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), - }, + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), }, - ]; + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.deletePost(1)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); - }); + const store = mockStore({ initialState }); + store + .dispatch(actions.deletePost(1)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); +}); }); diff --git a/studio/src/__tests__/actions/sachFactChecks.js b/studio/src/__tests__/actions/sachFactChecks.js index 5025f8760..e4e2ce27b 100644 --- a/studio/src/__tests__/actions/sachFactChecks.js +++ b/studio/src/__tests__/actions/sachFactChecks.js @@ -67,7 +67,7 @@ const factcheck = { sitename: 'Full Fact', tags: ['employment', 'United Kingdom'], text: - 'That’s correct. The ONS’ best estimate for the number of non-UK born workers rose by 431,000 between the end of 2015 and the end of 2016.\n“Another 431,000 migrants working in Britain”\nDaily Express, paper edition, 16 February 2017\n“British-born workers PLUNGE as foreign workers RISE by 431,000”\nDaily Express, online edition, 16 February 2017\nSeveral media outlets reported the most recent set of employment figures this morning, and the Daily Express featured the story on its front page. The figures reported are correct, but there’s a lot of uncertainty around some of the latest changes.\nThe good news is we haven’t seen anyone make the kind of mistakes we’ve seen in the past when it comes to reporting employment figures.\nAs the Office for National Statistics says prominently, these statistics don’t tell us how many people have lost jobs or how many people have got a new one, they just tell us the final change in the headcount of people who have jobs.\nThese estimates are very uncertain\nThe UK had 431,000 more foreign-born workers at the end of 2016 than it had a year beforehand, according to estimates from the Office for National Statistics (ONS).\nMeanwhile, its estimate for the number of workers born inside the UK dropped by 120,000.\nSo foreign-born workers rose in number while British born workers fell? Not quite.\nThe difference between these two changes is that the first is big enough for us to be confident it’s genuine, the second isn’t.\nThe estimates are based on a survey, so there’s a grey area around the ONS’ best estimate for the numbers of different groups of workers.\nThe estimate for UK-born workers and UK nationals in work would have to change by more than 200,000 for us to be reasonably confident that we were seeing a genuine change in the real world.\nThat may sound like a surprisingly big margin. But remember: there are an estimated 26 million UK-born workers or 28 million UK citizens in work. A change of less than 200,000 is difficult to detect with a lot of confidence, based on these figures.\nThere’s more than one definition of ‘foreigner’\nThe Office for National Statistics puts out employment figures for two groups which you might associate with the word, ‘foreigner’:\nPeople born inside / outside the UK\nUK / non-UK nationals\nThe estimated number of British-born workers didn’t ‘plunge’ on both definitions.\nThe best estimate for the number of UK-born workers fell by 120,000, and rose by 70,000 for UK nationals. Like before, these changes are too small for us to be confident they’ve actually happened.', + "That’s correct. The ONS’ best estimate for the number of non-UK born workers rose by 431,000 between the end of 2015 and the end of 2016.\n“Another 431,000 migrants working in Britain”\nDaily Express, paper edition, 16 February 2017\n“British-born workers PLUNGE as foreign workers RISE by 431,000”\nDaily Express, online edition, 16 February 2017\nSeveral media outlets reported the most recent set of employment figures this morning, and the Daily Express featured the story on its front page. The figures reported are correct, but there’s a lot of uncertainty around some of the latest changes.\nThe good news is we haven’t seen anyone make the kind of mistakes we’ve seen in the past when it comes to reporting employment figures.\nAs the Office for National Statistics says prominently, these statistics don’t tell us how many people have lost jobs or how many people have got a new one, they just tell us the final change in the headcount of people who have jobs.\nThese estimates are very uncertain\nThe UK had 431,000 more foreign-born workers at the end of 2016 than it had a year beforehand, according to estimates from the Office for National Statistics (ONS).\nMeanwhile, its estimate for the number of workers born inside the UK dropped by 120,000.\nSo foreign-born workers rose in number while British born workers fell? Not quite.\nThe difference between these two changes is that the first is big enough for us to be confident it’s genuine, the second isn’t.\nThe estimates are based on a survey, so there’s a grey area around the ONS’ best estimate for the numbers of different groups of workers.\nThe estimate for UK-born workers and UK nationals in work would have to change by more than 200,000 for us to be reasonably confident that we were seeing a genuine change in the real world.\nThat may sound like a surprisingly big margin. But remember: there are an estimated 26 million UK-born workers or 28 million UK citizens in work. A change of less than 200,000 is difficult to detect with a lot of confidence, based on these figures.\nThere’s more than one definition of ‘foreigner’\nThe Office for National Statistics puts out employment figures for two groups which you might associate with the word, ‘foreigner’:\nPeople born inside / outside the UK\nUK / non-UK nationals\nThe estimated number of British-born workers didn’t ‘plunge’ on both definitions.\nThe best estimate for the number of UK-born workers fell by 120,000, and rose by 70,000 for UK nationals. Like before, these changes are too small for us to be confident they’ve actually happened.", title: 'Reports on employment figures are accurate, but not the whole picture', translation: {}, }; diff --git a/studio/src/__tests__/actions/spaces.js b/studio/src/__tests__/actions/spaces.js index c3fc885ca..0b42ad36d 100644 --- a/studio/src/__tests__/actions/spaces.js +++ b/studio/src/__tests__/actions/spaces.js @@ -279,6 +279,7 @@ describe('spaces actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.delete).toHaveBeenCalledWith(types.API_DELETE_SPACE + '/1'); }); + it('should create actions to set selected space', () => { const space = { id: 1, name: 'Space' }; @@ -302,4 +303,57 @@ describe('spaces actions', () => { store.dispatch(actions.setSelectedSpace(space)); expect(store.getActions()).toEqual(expectedActions); }); + + it('should create actions to fetch space users and update the selected space', () => { + const users = [{ id: 11, name: 'User 1' }, { id: 12, name: 'User 2' }]; + const space = { id: 1, name: 'Space', users }; + const resp = { data: users }; + axios.get.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.LOADING_SPACES, + }, + { + type: types.ADD_SPACE_USERS, + payload: { + id: 1, + data: users + }, + } + ]; + + const store = mockStore({ ...initialState, spaces: { selected: space.id } }); + store + .dispatch(actions.getSpaceUsers()) + .then(() => expect(store.getActions()).toEqual(expectedActions)) + expect(axios.get).toHaveBeenCalledWith(`/core/spaces/${space.id}/users`); + }); + + it('should create actions to fetch space users and update the selected space when failure', () => { + const errorMessage = 'Failed to fetch space users'; + axios.get.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.LOADING_SPACES, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + ]; + + const store = mockStore({ ...initialState, spaces: { selected: 1 } }); + store + .dispatch(actions.getSpaceUsers()) + .then(() => expect(store.getActions()).toEqual(expectedActions)) + expect(axios.get).toHaveBeenCalledWith(`/core/spaces/1/users`); + }); + }); diff --git a/studio/src/actions/posts.js b/studio/src/actions/posts.js index 3aecd4ecb..50a836e3e 100644 --- a/studio/src/actions/posts.js +++ b/studio/src/actions/posts.js @@ -221,7 +221,9 @@ export const publish = (data) => { .post(POSTS_API + '/publish', data) .then((response) => { let post = response.data; - if (typeof post.description !== 'object') { + if ((typeof post.description !== 'object' && post.hasOwnProperty('description_html')) + || (!post.description.hasOwnProperty('json') && !post.description.hasOwnProperty('html')) + ) { post.description = { json: post.description, html: post.description_html }; delete post.description_html; } From 847beff2a8082e785fda73c026abd0a2f46b47f0 Mon Sep 17 00:00:00 2001 From: Ishpaul Singhtest
" } - }; + const episode = { + id: 1, title: 'Episode', podcast: podcast, description: { json: { "hello": "test" }, html: "test
" } + }; + const resp = { data: episode }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_EPISODES_LOADING, + payload: true, + }, + { + type: ADD_PODCASTS, + payload: [podcast], + }, + { + type: types.UPDATE_EPISODE, + payload: { id: 1, title: 'Episode', podcast: 1, description: { json: { "hello": "test" }, html: "test
" } }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Episode updated', + time: Date.now(), + }, + }, + { + type: types.SET_EPISODES_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updateEpisode(episode)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.EPISODES_API + '/1', episode); + }); + it('should create actions to update episode success with description and html', () => { + const podcast = { id: 1 }; + const episode = { + id: 1, title: 'Episode', podcast: podcast, description: { "hello": "test" }, description_html: "test
" + }; const resp = { data: episode }; axios.put.mockResolvedValue(resp); @@ -319,6 +362,49 @@ describe('episodes actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.EPISODES_API + '/1', episode); }); + it('should create actions to update episode success without description and html', () => { + const podcast = { id: 1 }; + const episode = { + id: 1, title: 'Episode', podcast: podcast + }; + const resp = { data: episode }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_EPISODES_LOADING, + payload: true, + }, + { + type: ADD_PODCASTS, + payload: [podcast], + }, + { + type: types.UPDATE_EPISODE, + payload: { id: 1, title: 'Episode', podcast: 1, description: { json: undefined , html: undefined } }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Episode updated', + time: Date.now(), + }, + }, + { + type: types.SET_EPISODES_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updateEpisode(episode)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.EPISODES_API + '/1', episode); + }); + it('should create actions to update episode failure', () => { const episode = { id: 1, title: 'Episode' }; const errorMessage = 'Failed to update episode'; @@ -352,7 +438,7 @@ describe('episodes actions', () => { }); it('should create actions to update episode success without podcast and without description ', () => { const podcast = {}; - const description = {json: undefined, html: undefined}; + const description = { json: undefined, html: undefined }; const episode = { id: 1, title: 'Episode', podcast: podcast, description: description }; const resp = { data: episode }; axios.put.mockResolvedValue(resp); diff --git a/studio/src/__tests__/actions/pages.js b/studio/src/__tests__/actions/pages.js index 9a1e39c08..68aebd395 100644 --- a/studio/src/__tests__/actions/pages.js +++ b/studio/src/__tests__/actions/pages.js @@ -919,6 +919,155 @@ describe('pages actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.PAGES_API + '/1', page1); }); + it('should create actions to update page success with description and html', () => { + const data2 = { ...page1, description: { "hello": "world" }, description_html: "hello world
" }; + data2.status = 'draft'; + const resp = { data: data2 }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_PAGES_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { id: 31, name: 'category 31', medium: 311, description: { json: { "hello": 'world' }, html: "hello world
" } }, + { id: 32, name: 'category 32', medium: undefined, description: { json: undefined, html: undefined } }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_PAGE, + payload: { + id: 1, + name: 'Page 1', + status: 'draft', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: { id: 41, name: 'Format 1' }, + medium: 51, + description: { + json: { "hello": 'world' }, html: "hello world
" + }, + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Draft Saved', + time: Date.now(), + }, + }, + { + type: types.SET_PAGES_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePage(page1)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.PAGES_API + '/1', page1); + }); + + it('should create actions to update page success with description and html', () => { + const data2 = { ...page1 }; + data2.status = 'draft'; + const resp = { data: data2 }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_PAGES_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { id: 31, name: 'category 31', medium: 311, description: { json: { "hello": 'world' }, html: "hello world
" } }, + { id: 32, name: 'category 32', medium: undefined, description: { json: undefined, html: undefined } }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_PAGE, + payload: { + id: 1, + name: 'Page 1', + status: 'draft', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: { id: 41, name: 'Format 1' }, + medium: 51, + description: { + json: undefined , html: undefined + }, + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Draft Saved', + time: Date.now(), + }, + }, + { + type: types.SET_PAGES_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePage(page1)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.PAGES_API + '/1', page1); + }); it('should create actions to update page success with ready status', () => { const data2 = { ...page1, description: { json: { "hello": "world" }, html: "hello world
" } }; diff --git a/studio/src/__tests__/actions/posts.js b/studio/src/__tests__/actions/posts.js index 9356b66c5..01119e91d 100644 --- a/studio/src/__tests__/actions/posts.js +++ b/studio/src/__tests__/actions/posts.js @@ -1397,6 +1397,296 @@ describe('posts actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); }); + it('should create actions to publish post success with description and description_html', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { "hello": "test" }, + description_html: "hello
", + }; + + const resp = { data: post_local }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: 51, + claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Post published', + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.publishPost(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); + }); + + it('should create actions to publish post success without description and description_html', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + }; + + const resp = { data: post_local }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: 51, + claims: [61], + description: { + json: undefined, + html: undefined + } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Post published', + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.publishPost(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); + }); + it('should create actions to publish post success without medium', () => { const post_local = { name: 'Post 1', @@ -1538,6 +1828,7 @@ describe('posts actions', () => { post_without_media, ); }); + it('should create actions to publish success', () => { const post_local = { name: 'Post 1', diff --git a/studio/src/__tests__/actions/ratings.js b/studio/src/__tests__/actions/ratings.js index 556c77411..426846ded 100644 --- a/studio/src/__tests__/actions/ratings.js +++ b/studio/src/__tests__/actions/ratings.js @@ -448,7 +448,7 @@ describe('ratings actions', () => { }, { type: types.UPDATE_RATING, - payload: { id: 1, name: 'Rating', medium: 4, description}, + payload: { id: 1, name: 'Rating', medium: 4, description }, }, { type: ADD_NOTIFICATION, @@ -471,6 +471,92 @@ describe('ratings actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.RATINGS_API + '/1', rating); }); + + + it('should create actions to update rating with medium and description', () => { + const medium = { id: 4, name: 'medium' }; + const description = { "hello": "test" } + const description_html = "test
" + const rating = { id: 1, name: 'Rating', medium: medium, description, description_html }; + const resp = { data: rating }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_RATINGS_LOADING, + payload: true, + }, + { + type: ADD_MEDIA, + payload: [medium], + }, + { + type: types.UPDATE_RATING, + payload: { id: 1, name: 'Rating', medium: 4, description: { json: { "hello": "test" }, html: "test
" } }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Rating updated', + time: Date.now(), + }, + }, + { + type: types.SET_RATINGS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updateRating(rating)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.RATINGS_API + '/1', rating); + }); + + it('should create actions to update rating without description', () => { + const medium = { id: 4, name: 'medium' }; + const rating = { id: 1, name: 'Rating', medium: medium }; + const resp = { data: rating }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_RATINGS_LOADING, + payload: true, + }, + { + type: ADD_MEDIA, + payload: [medium], + }, + { + type: types.UPDATE_RATING, + payload: { id: 1, name: 'Rating', medium: 4, description: { json: undefined, html: undefined } }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Rating updated', + time: Date.now(), + }, + }, + { + type: types.SET_RATINGS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updateRating(rating)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.RATINGS_API + '/1', rating); + }); + it('should create actions to update rating failure', () => { const rating = { id: 1, name: 'Rating' }; const errorMessage = 'Failed to update rating'; diff --git a/studio/src/actions/pages.js b/studio/src/actions/pages.js index 4880c3436..c8361ad2d 100644 --- a/studio/src/actions/pages.js +++ b/studio/src/actions/pages.js @@ -183,8 +183,8 @@ export const addPage = (data) => { page.status === 'publish' ? dispatch(addSuccessNotification(`Page Published`)) : page.status === 'draft' - ? dispatch(addSuccessNotification('Page added')) - : dispatch(addSuccessNotification('Page added & Ready to Publish')); + ? dispatch(addSuccessNotification('Page added')) + : dispatch(addSuccessNotification('Page added & Ready to Publish')); return page; }) .catch((error) => { @@ -200,7 +200,15 @@ export const updatePage = (data) => { .put(PAGES_API + '/' + data.id, data) .then((response) => { let page = response.data; - // ! not needed + if ((response.data.description === undefined) + || (typeof response.data.description !== 'object' && response.data.hasOwnProperty('description_html')) + || (!response.data.description.hasOwnProperty('json') && !response.data.description.hasOwnProperty('html'))) { + response.data.description = { + json: response.data.description, + html: response.data.description_html, + }; + delete response.data.description_html + } // page.description = { json: page.description, html: page.description_html }; // delete page.description_html; dispatch(addTags(page.tags)); @@ -220,8 +228,8 @@ export const updatePage = (data) => { page.status === 'publish' ? dispatch(addSuccessNotification(`Page Published`)) : page.status === 'draft' - ? dispatch(addSuccessNotification('Draft Saved')) - : dispatch(addSuccessNotification('Draft saved & Ready to Publish')); + ? dispatch(addSuccessNotification('Draft Saved')) + : dispatch(addSuccessNotification('Draft saved & Ready to Publish')); }) .catch((error) => { dispatch(addErrorNotification(getError(error))); diff --git a/studio/src/actions/posts.js b/studio/src/actions/posts.js index 50a836e3e..8daeb5475 100644 --- a/studio/src/actions/posts.js +++ b/studio/src/actions/posts.js @@ -221,11 +221,14 @@ export const publish = (data) => { .post(POSTS_API + '/publish', data) .then((response) => { let post = response.data; - if ((typeof post.description !== 'object' && post.hasOwnProperty('description_html')) - || (!post.description.hasOwnProperty('json') && !post.description.hasOwnProperty('html')) - ) { - post.description = { json: post.description, html: post.description_html }; - delete post.description_html; + if ((response.data.description === undefined) + || (typeof response.data.description !== 'object' && response.data.hasOwnProperty('description_html')) + || (!response.data.description.hasOwnProperty('json') && !response.data.description.hasOwnProperty('html'))) { + response.data.description = { + json: response.data.description, + html: response.data.description_html, + }; + delete response.data.description_html } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); @@ -261,9 +264,14 @@ export const addTemplate = (data) => { .post(POSTS_API + '/templates', data) .then((response) => { let post = response.data; - if (typeof post.description !== 'object') { - post.description = { json: post.description, html: post.description_html }; - delete post.description_html; + if ((response.data.description === undefined) + || (typeof response.data.description !== 'object' && response.data.hasOwnProperty('description_html')) + || (!response.data.description.hasOwnProperty('json') && !response.data.description.hasOwnProperty('html'))) { + response.data.description = { + json: response.data.description, + html: response.data.description_html, + }; + delete response.data.description_html } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); @@ -299,9 +307,14 @@ export const publishPost = (data) => { .put(POSTS_API + '/' + data.id + '/publish', data) .then((response) => { let post = response.data; - if (typeof post.description !== 'object') { - post.description = { json: post.description, html: post.description_html }; - delete post.description_html; + if ((response.data.description === undefined) + || (response.data.hasOwnProperty('description_html')) + || (!response.data.description.hasOwnProperty('json') && !response.data.description.hasOwnProperty('html'))) { + response.data.description = { + json: response.data.description, + html: response.data.description_html, + }; + delete response.data.description_html } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); @@ -337,9 +350,14 @@ export const updatePost = (data) => { .put(POSTS_API + '/' + data.id, data) .then((response) => { let post = response.data; - if (typeof post.description !== 'object') { - post.description = { json: post.description, html: post.description_html }; - delete post.description_html; + if ((response.data.description === undefined) + || (response.data.hasOwnProperty('description_html')) + || (!response.data.description.hasOwnProperty('json') && !response.data.description.hasOwnProperty('html'))) { + response.data.description = { + json: response.data.description, + html: response.data.description_html, + }; + delete response.data.description_html } dispatch(addTags(post.tags)); dispatch(addCategories(post.categories)); diff --git a/studio/src/actions/ratings.js b/studio/src/actions/ratings.js index 8422108a0..11f26c2cf 100644 --- a/studio/src/actions/ratings.js +++ b/studio/src/actions/ratings.js @@ -131,9 +131,14 @@ export const updateRating = (data) => { .then((response) => { const rating = response.data; if (rating.medium) dispatch(addMedia([rating.medium])); - if (typeof rating.description === "string" || rating.description === undefined) { - rating.description = { json: rating.description, html: rating.description_html }; - delete rating.description_html; + if ( (response.data.description === undefined) + || (response.data.hasOwnProperty('description_html')) + || (!response.data.description.hasOwnProperty('json') && !response.data.description.hasOwnProperty('html'))) { + response.data.description = { + json: response.data.description, + html: response.data.description_html, + }; + delete response.data.description_html } dispatch(addRating(UPDATE_RATING, { ...rating, medium: rating.medium?.id })); dispatch(addSuccessNotification('Rating updated')); From ebd3b8e6a4e65ae93a05d5f7bf8d41ce3d435a4f Mon Sep 17 00:00:00 2001 From: Ishpaul Singhhello
", - } + description: { "hello": "test" }, + description_html: "hello
", }; - const resp = { data: post_local }; + const data2 = { ...post_local }; + data2.status = 'draft'; + const resp = { data: data2 }; axios.put.mockResolvedValue(resp); const expectedActions = [ @@ -1364,6 +1364,7 @@ describe('posts actions', () => { payload: { id: 1, name: 'Post 1', + status: 'draft', authors: [11], tags: [21, 22], categories: [31, 32], @@ -1381,7 +1382,7 @@ describe('posts actions', () => { payload: { type: 'success', title: 'Success', - message: 'Post published', + message: 'Draft Saved', time: Date.now(), }, }, @@ -1393,11 +1394,11 @@ describe('posts actions', () => { const store = mockStore({ initialState }); store - .dispatch(actions.publishPost(post)) + .dispatch(actions.updatePost(data2)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', data2); }); - it('should create actions to publish post success with description and description_html', () => { + it('should create actions to update post success with descritption and html', () => { const post_local = { name: 'Post 1', authors: [{ id: 11, name: 'Author 1' }], @@ -1420,11 +1421,11 @@ describe('posts actions', () => { }, ], id: 1, - description: { "hello": "test" }, - description_html: "hello
", }; - const resp = { data: post_local }; + const data2 = { ...post_local }; + data2.status = 'draft'; + const resp = { data: data2 }; axios.put.mockResolvedValue(resp); const expectedActions = [ @@ -1509,6 +1510,7 @@ describe('posts actions', () => { payload: { id: 1, name: 'Post 1', + status: 'draft', authors: [11], tags: [21, 22], categories: [31, 32], @@ -1516,8 +1518,8 @@ describe('posts actions', () => { medium: 51, claims: [61], description: { - json: { "hello": "test" }, - html: "hello
", + json: undefined, + html: undefined } }, }, @@ -1526,7 +1528,7 @@ describe('posts actions', () => { payload: { type: 'success', title: 'Success', - message: 'Post published', + message: 'Draft Saved', time: Date.now(), }, }, @@ -1538,12 +1540,12 @@ describe('posts actions', () => { const store = mockStore({ initialState }); store - .dispatch(actions.publishPost(post)) + .dispatch(actions.updatePost(data2)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', data2); }); - it('should create actions to publish post success without description and description_html', () => { + it('should create actions to publish post success', () => { const post_local = { name: 'Post 1', authors: [{ id: 11, name: 'Author 1' }], @@ -1566,6 +1568,10 @@ describe('posts actions', () => { }, ], id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } }; const resp = { data: post_local }; @@ -1660,8 +1666,8 @@ describe('posts actions', () => { medium: 51, claims: [61], description: { - json: undefined, - html: undefined + json: { "hello": "test" }, + html: "hello
", } }, }, @@ -1686,8 +1692,7 @@ describe('posts actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); }); - - it('should create actions to publish post success without medium', () => { + it('should create actions to publish post success with description and description_html', () => { const post_local = { name: 'Post 1', authors: [{ id: 11, name: 'Author 1' }], @@ -1700,6 +1705,7 @@ describe('posts actions', () => { { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, ], format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, claims: [ { id: 61, @@ -1709,6 +1715,8 @@ describe('posts actions', () => { }, ], id: 1, + description: { "hello": "test" }, + description_html: "hello
", }; const resp = { data: post_local }; @@ -1787,6 +1795,10 @@ describe('posts actions', () => { type: ADD_FORMATS, payload: [{ id: 41, name: 'Format 1' }], }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, { type: types.ADD_POST, payload: { @@ -1796,11 +1808,11 @@ describe('posts actions', () => { tags: [21, 22], categories: [31, 32], format: 41, - medium: undefined, + medium: 51, claims: [61], description: { - json: undefined, - html: undefined, + json: { "hello": "test" }, + html: "hello
", } }, }, @@ -1821,15 +1833,12 @@ describe('posts actions', () => { const store = mockStore({ initialState }); store - .dispatch(actions.publishPost(post_without_media)) + .dispatch(actions.publishPost(post)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith( - types.POSTS_API + '/123' + '/publish', - post_without_media, - ); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); }); - - it('should create actions to publish success', () => { + + it('should create actions to publish post success without description and description_html', () => { const post_local = { name: 'Post 1', authors: [{ id: 11, name: 'Author 1' }], @@ -1852,14 +1861,10 @@ describe('posts actions', () => { }, ], id: 1, - description: { - json: { "hello": "test" }, - html: "hello
", - } }; const resp = { data: post_local }; - axios.post.mockResolvedValue(resp); + axios.put.mockResolvedValue(resp); const expectedActions = [ { @@ -1950,8 +1955,8 @@ describe('posts actions', () => { medium: 51, claims: [61], description: { - json: { "hello": "test" }, - html: "hello
", + json: undefined, + html: undefined } }, }, @@ -1972,12 +1977,12 @@ describe('posts actions', () => { const store = mockStore({ initialState }); store - .dispatch(actions.publish(post_local)) + .dispatch(actions.publishPost(post)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post_local); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); }); - it('should handle post with description and description_html', () => { + it('should create actions to publish post success without medium', () => { const post_local = { name: 'Post 1', authors: [{ id: 11, name: 'Author 1' }], @@ -1990,7 +1995,6 @@ describe('posts actions', () => { { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, ], format: { id: 41, name: 'Format 1' }, - medium: { id: 51, name: 'Medium 1' }, claims: [ { id: 61, @@ -2000,12 +2004,10 @@ describe('posts actions', () => { }, ], id: 1, - description: { "hello": "test" }, - description_html: "hello
" }; const resp = { data: post_local }; - axios.post.mockResolvedValue(resp); + axios.put.mockResolvedValue(resp); const expectedActions = [ { @@ -2080,10 +2082,6 @@ describe('posts actions', () => { type: ADD_FORMATS, payload: [{ id: 41, name: 'Format 1' }], }, - { - type: ADD_MEDIA, - payload: [{ id: 51, name: 'Medium 1' }], - }, { type: types.ADD_POST, payload: { @@ -2093,11 +2091,11 @@ describe('posts actions', () => { tags: [21, 22], categories: [31, 32], format: 41, - medium: 51, + medium: undefined, claims: [61], description: { - json: { "hello": "test" }, - html: "hello
", + json: undefined, + html: undefined, } }, }, @@ -2116,678 +2114,975 @@ describe('posts actions', () => { }, ]; - const store = mockStore({initialState}); + const store = mockStore({ initialState }); store - .dispatch(actions.publish(post_local)) + .dispatch(actions.publishPost(post_without_media)) .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post_local); -}); - - -it('should create actions to publish failure', () => { - const errorMessage = 'Failed to publish post'; - axios.post.mockRejectedValue(new Error(errorMessage)); - - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), - }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; - - const store = mockStore({ initialState }); - store - .dispatch(actions.publish(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post); -}); + expect(axios.put).toHaveBeenCalledWith( + types.POSTS_API + '/123' + '/publish', + post_without_media, + ); + }); -it('should create actions to template success', () => { - const post_local = { - name: 'Post 1', - authors: [{ id: 11, name: 'Author 1' }], - tags: [ - { id: 21, name: 'Tag 21' }, - { id: 22, name: 'Tag 22' }, - ], - categories: [ - { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, - { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, - ], - format: { id: 41, name: 'Format 1' }, - medium: { id: 51, name: 'Medium 1' }, - claims: [ - { - id: 61, - name: 'Claim 1', - claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, - rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, - }, - ], - id: 1, - description: { - json: { "hello": "test" }, - html: "hello
", - } - }; - const resp = { data: post_local }; - axios.post.mockResolvedValue(resp); - - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [ + it('should create actions to publish success', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ { id: 21, name: 'Tag 21' }, { id: 22, name: 'Tag 22' }, ], - }, - { - type: ADD_MEDIA, - payload: [{ id: 311, name: 'Category-Medium-311' }], - }, - { - type: ADD_CATEGORIES, - payload: [ + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ { - id: 31, name: 'category 31', medium: 311, - description: { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }; + + const resp = { data: post_local }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { json: undefined, html: undefined, } - }, - { - id: 32, name: 'category 32', medium: undefined, + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: 51, + claims: [61], description: { json: { "hello": "test" }, html: "hello
", } }, - ], - }, - { - type: ADD_AUTHORS, - payload: [{ id: 11, name: 'Author 1' }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 621, name: 'Medium-Claimant 1' }], - }, - { - type: ADD_CLAIMANTS, - payload: [{ - id: 601, name: 'Claimant 1', medium: 621, description: { - json: undefined, - html: undefined, - } - }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 622, name: 'Medium-Rating 1' }], - }, - { - type: ADD_RATINGS, - payload: [{ - id: 602, name: 'Rating 1', medium: 622, description: { - json: undefined, - html: undefined, - } - }], - }, - { - type: ADD_CLAIMS, - payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], - }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 51, name: 'Medium 1' }], - }, - { - type: types.ADD_POST, - payload: { - id: 1, - name: 'Post 1', - authors: [11], - tags: [21, 22], - categories: [31, 32], - format: 41, - medium: 51, - claims: [61], - description: { - json: { "hello": "test" }, - html: "hello
", - } }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Template created', - time: Date.now(), + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Post published', + time: Date.now(), + }, }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.addTemplate(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); -}); + const store = mockStore({ initialState }); + store + .dispatch(actions.publish(post_local)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post_local); + }); -it('should create actions to template success without medium', () => { - const post_local = { - name: 'Post 1', - authors: [{ id: 11, name: 'Author 1' }], - tags: [ - { id: 21, name: 'Tag 21' }, - { id: 22, name: 'Tag 22' }, - ], - categories: [ - { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, - { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, - ], - format: { id: 41, name: 'Format 1' }, - claims: [ - { - id: 61, - name: 'Claim 1', - claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, - rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, - }, - ], - id: 1, - }; - - const resp = { data: post_local }; - axios.post.mockResolvedValue(resp); - - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [ + it('should handle post with description and description_html', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ { id: 21, name: 'Tag 21' }, { id: 22, name: 'Tag 22' }, ], - }, - { - type: ADD_MEDIA, - payload: [{ id: 311, name: 'Category-Medium-311' }], - }, - { - type: ADD_CATEGORIES, - payload: [ + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ { - id: 31, name: 'category 31', medium: 311, - description: { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { "hello": "test" }, + description_html: "hello
" + }; + + const resp = { data: post_local }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { json: undefined, html: undefined, } - }, - { - id: 32, name: 'category 32', medium: undefined, + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: 51, + claims: [61], description: { json: { "hello": "test" }, html: "hello
", } }, - ], - }, - { - type: ADD_AUTHORS, - payload: [{ id: 11, name: 'Author 1' }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 621, name: 'Medium-Claimant 1' }], - }, - { - type: ADD_CLAIMANTS, - payload: [{ - id: 601, name: 'Claimant 1', medium: 621, description: { - json: undefined, - html: undefined, - } - }], - }, - { - type: ADD_MEDIA, - payload: [{ id: 622, name: 'Medium-Rating 1' }], - }, - { - type: ADD_RATINGS, - payload: [{ - id: 602, name: 'Rating 1', medium: 622, description: { - json: undefined, - html: undefined, - } - }], - }, - { - type: ADD_CLAIMS, - payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], - }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], - }, - { - type: types.ADD_POST, - payload: { - id: 1, - name: 'Post 1', - authors: [11], - tags: [21, 22], - categories: [31, 32], - format: 41, - medium: undefined, - claims: [61], - description: { - json: undefined, - html: undefined, - } }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Template created', - time: Date.now(), + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Post published', + time: Date.now(), + }, }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; - - const store = mockStore({ initialState }); - store - .dispatch(actions.addTemplate(post_local)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post_local); -}); + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; -it('should create actions to template failure', () => { - const errorMessage = 'Failed to publish post'; - axios.post.mockRejectedValue(new Error(errorMessage)); + const store = mockStore({ initialState }); + store + .dispatch(actions.publish(post_local)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post_local); + }); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), - }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.addTemplate(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); -}); + it('should create actions to publish failure', () => { + const errorMessage = 'Failed to publish post'; + axios.post.mockRejectedValue(new Error(errorMessage)); -it('should create actions to update success without any optional fields', () => { - const post_without_fields = { ...post }; - post_without_fields.categories = []; - post_without_fields.authors = []; - post_without_fields.tags = []; - post_without_fields.claims = []; - post_without_fields.medium = undefined; - post_without_fields.status = 'publish'; + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const resp = { data: post_without_fields }; - axios.put.mockResolvedValue(resp); + const store = mockStore({ initialState }); + store + .dispatch(actions.publish(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/publish', post); + }); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CATEGORIES, - payload: [], - }, - { - type: ADD_AUTHORS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CLAIMANTS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_RATINGS, - payload: [], - }, - { - type: ADD_CLAIMS, - payload: [], - }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], - }, - { - type: types.ADD_POST, - payload: { - id: 1, - name: 'Post 1', - authors: [], - tags: [], - categories: [], - format: 41, - medium: undefined, - claims: [], - status: 'publish', - description: { - json: undefined, - html: undefined, - } + it('should create actions to template success', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + medium: { id: 51, name: 'Medium 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }; + const resp = { data: post_local }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 51, name: 'Medium 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: 51, + claims: [61], + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Template created', + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.addTemplate(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); + }); + + it('should create actions to template success without medium', () => { + const post_local = { + name: 'Post 1', + authors: [{ id: 11, name: 'Author 1' }], + tags: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + categories: [ + { id: 31, name: 'category 31', medium: { id: 311, name: 'Category-Medium-311' } }, + { id: 32, name: 'category 32', description: { "hello": "test" }, description_html: "hello
" }, + ], + format: { id: 41, name: 'Format 1' }, + claims: [ + { + id: 61, + name: 'Claim 1', + claimant: { id: 601, name: 'Claimant 1', medium: { id: 621, name: 'Medium-Claimant 1' } }, + rating: { id: 602, name: 'Rating 1', medium: { id: 622, name: 'Medium-Rating 1' } }, + }, + ], + id: 1, + }; + + const resp = { data: post_local }; + axios.post.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [ + { id: 21, name: 'Tag 21' }, + { id: 22, name: 'Tag 22' }, + ], + }, + { + type: ADD_MEDIA, + payload: [{ id: 311, name: 'Category-Medium-311' }], + }, + { + type: ADD_CATEGORIES, + payload: [ + { + id: 31, name: 'category 31', medium: 311, + description: { + json: undefined, + html: undefined, + } + }, + { + id: 32, name: 'category 32', medium: undefined, + description: { + json: { "hello": "test" }, + html: "hello
", + } + }, + ], + }, + { + type: ADD_AUTHORS, + payload: [{ id: 11, name: 'Author 1' }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 621, name: 'Medium-Claimant 1' }], + }, + { + type: ADD_CLAIMANTS, + payload: [{ + id: 601, name: 'Claimant 1', medium: 621, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_MEDIA, + payload: [{ id: 622, name: 'Medium-Rating 1' }], + }, + { + type: ADD_RATINGS, + payload: [{ + id: 602, name: 'Rating 1', medium: 622, description: { + json: undefined, + html: undefined, + } + }], + }, + { + type: ADD_CLAIMS, + payload: [{ id: 61, name: 'Claim 1', claimant: 601, rating: 602 }], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [11], + tags: [21, 22], + categories: [31, 32], + format: 41, + medium: undefined, + claims: [61], + description: { + json: undefined, + html: undefined, + } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Template created', + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.addTemplate(post_local)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post_local); + }); + + it('should create actions to template failure', () => { + const errorMessage = 'Failed to publish post'; + axios.post.mockRejectedValue(new Error(errorMessage)); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.addTemplate(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.post).toHaveBeenCalledWith(types.POSTS_API + '/templates', post); + }); + + it('should create actions to update success without any optional fields', () => { + const post_without_fields = { ...post }; + post_without_fields.categories = []; + post_without_fields.authors = []; + post_without_fields.tags = []; + post_without_fields.claims = []; + post_without_fields.medium = undefined; + post_without_fields.status = 'publish'; + + const resp = { data: post_without_fields }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, + }, + { + type: ADD_TAGS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_CATEGORIES, + payload: [], + }, + { + type: ADD_AUTHORS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_CLAIMANTS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_RATINGS, + payload: [], + }, + { + type: ADD_CLAIMS, + payload: [], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [], + tags: [], + categories: [], + format: 41, + medium: undefined, + claims: [], + status: 'publish', + description: { + json: undefined, + html: undefined, + } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Format 1 Published', + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post_without_fields)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); + }); + it('should create actions to update success without any optional fields with ready status', () => { + const post_without_fields = { ...post }; + post_without_fields.categories = []; + post_without_fields.authors = []; + post_without_fields.tags = []; + post_without_fields.claims = []; + post_without_fields.medium = undefined; + post_without_fields.status = 'ready'; + + const resp = { data: post_without_fields }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Format 1 Published', - time: Date.now(), + { + type: ADD_TAGS, + payload: [], }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; - - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post_without_fields)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); -}); -it('should create actions to update success without any optional fields with ready status', () => { - const post_without_fields = { ...post }; - post_without_fields.categories = []; - post_without_fields.authors = []; - post_without_fields.tags = []; - post_without_fields.claims = []; - post_without_fields.medium = undefined; - post_without_fields.status = 'ready'; - - const resp = { data: post_without_fields }; - axios.put.mockResolvedValue(resp); - - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_TAGS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CATEGORIES, - payload: [], - }, - { - type: ADD_AUTHORS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_CLAIMANTS, - payload: [], - }, - { - type: ADD_MEDIA, - payload: [], - }, - { - type: ADD_RATINGS, - payload: [], - }, - { - type: ADD_CLAIMS, - payload: [], - }, - { - type: ADD_FORMATS, - payload: [{ id: 41, name: 'Format 1' }], - }, - { - type: types.ADD_POST, - payload: { - id: 1, - name: 'Post 1', - authors: [], - tags: [], - categories: [], - format: 41, - medium: undefined, - claims: [], - status: 'ready', - description: { - json: undefined, - html: undefined, - } + { + type: ADD_MEDIA, + payload: [], }, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Draft saved & Ready to Publish', - time: Date.now(), + { + type: ADD_CATEGORIES, + payload: [], }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; + { + type: ADD_AUTHORS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_CLAIMANTS, + payload: [], + }, + { + type: ADD_MEDIA, + payload: [], + }, + { + type: ADD_RATINGS, + payload: [], + }, + { + type: ADD_CLAIMS, + payload: [], + }, + { + type: ADD_FORMATS, + payload: [{ id: 41, name: 'Format 1' }], + }, + { + type: types.ADD_POST, + payload: { + id: 1, + name: 'Post 1', + authors: [], + tags: [], + categories: [], + format: 41, + medium: undefined, + claims: [], + status: 'ready', + description: { + json: undefined, + html: undefined, + } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Draft saved & Ready to Publish', + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post_without_fields)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); -}); -it('should throw error on update post without required field format', () => { - const { format, ...post_without_format } = post; + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post_without_fields)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_fields); + }); + it('should throw error on update post without required field format', () => { + const { format, ...post_without_format } = post; - const resp = { data: post_without_format }; - axios.put.mockResolvedValue(resp); + const resp = { data: post_without_format }; + axios.put.mockResolvedValue(resp); - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post_without_format)) - .catch((err) => expect(err).toBeInstanceOf(TypeError)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_format); -}); -it('should create actions to update post failure', () => { - const errorMessage = 'Failed to update post'; - axios.put.mockRejectedValue(new Error(errorMessage)); + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post_without_format)) + .catch((err) => expect(err).toBeInstanceOf(TypeError)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post_without_format); + }); + it('should create actions to update post failure', () => { + const errorMessage = 'Failed to update post'; + axios.put.mockRejectedValue(new Error(errorMessage)); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.updatePost(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post); -}); -it('should create actions to publish post failure', () => { - const errorMessage = 'Failed to publish post'; - axios.put.mockRejectedValue(new Error(errorMessage)); + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePost(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1', post); + }); + it('should create actions to publish post failure', () => { + const errorMessage = 'Failed to publish post'; + axios.put.mockRejectedValue(new Error(errorMessage)); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, }, - }, - { - type: types.SET_POSTS_LOADING, - payload: false, - }, - ]; + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + { + type: types.SET_POSTS_LOADING, + payload: false, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.publishPost(post)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); -}); -it('should create actions to delete post success', () => { - axios.delete.mockResolvedValue(); + const store = mockStore({ initialState }); + store + .dispatch(actions.publishPost(post)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.POSTS_API + '/1' + '/publish', post); + }); + it('should create actions to delete post success', () => { + axios.delete.mockResolvedValue(); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: types.RESET_POSTS, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'success', - title: 'Success', - message: 'Post deleted', - time: Date.now(), + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, }, - }, - ]; + { + type: types.RESET_POSTS, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Post deleted', + time: Date.now(), + }, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.deletePost(1)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); -}); -it('should create actions to delete post failure', () => { - const errorMessage = 'Failed to delete post'; - axios.delete.mockRejectedValue(new Error(errorMessage)); + const store = mockStore({ initialState }); + store + .dispatch(actions.deletePost(1)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); + }); + it('should create actions to delete post failure', () => { + const errorMessage = 'Failed to delete post'; + axios.delete.mockRejectedValue(new Error(errorMessage)); - const expectedActions = [ - { - type: types.SET_POSTS_LOADING, - payload: true, - }, - { - type: ADD_NOTIFICATION, - payload: { - type: 'error', - title: 'Error', - message: errorMessage, - time: Date.now(), + const expectedActions = [ + { + type: types.SET_POSTS_LOADING, + payload: true, }, - }, - ]; + { + type: ADD_NOTIFICATION, + payload: { + type: 'error', + title: 'Error', + message: errorMessage, + time: Date.now(), + }, + }, + ]; - const store = mockStore({ initialState }); - store - .dispatch(actions.deletePost(1)) - .then(() => expect(store.getActions()).toEqual(expectedActions)); - expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); -}); + const store = mockStore({ initialState }); + store + .dispatch(actions.deletePost(1)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.delete).toHaveBeenCalledWith(types.POSTS_API + '/1'); + }); }); From d8aa3a58b83fbd0873780cc5ac44adceed304a19 Mon Sep 17 00:00:00 2001 From: Ishpaul Singhhello world
" } + const category = { id: 1, name: 'Category', medium: medium, description }; + const resp = { data: category }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_CATEGORIES_LOADING, + payload: true, + }, + { + type: ADD_MEDIA, + payload: [medium], + }, + { + type: types.UPDATE_CATEGORY, + payload: { id: 1, name: 'Category', medium: 4, description }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Category updated', + time: Date.now(), + }, + }, + { + type: types.SET_CATEGORIES_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updateCategory(category)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.CATEGORIES_API + '/1', category); + }); + it('should create actions to update category with medium and description not modified success', () => { + const medium = { id: 4, name: 'mediumm' }; + const description_modified = { json: { "hello": "world" }, html: "hello world
" } + const description = description_modified.json + const description_html = description_modified.html + const category = { id: 1, name: 'Category', medium: medium, description, description_html }; + const resp = { data: category }; + axios.put.mockResolvedValue(resp); + + const expectedActions = [ + { + type: types.SET_CATEGORIES_LOADING, + payload: true, + }, + { + type: ADD_MEDIA, + payload: [medium], + }, + { + type: types.UPDATE_CATEGORY, + payload: { id: 1, name: 'Category', medium: 4, description: description_modified }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Category updated', + time: Date.now(), + }, + }, + { + type: types.SET_CATEGORIES_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updateCategory(category)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.CATEGORIES_API + '/1', category); + }); + it('should create actions to update category failure', () => { const category = { id: 1, name: 'Category' }; const errorMessage = 'Failed to update category'; @@ -533,7 +618,7 @@ describe('categories actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.delete).toHaveBeenCalledWith(types.CATEGORIES_API + '/1'); }); - it('should create actions to add categories list with no medium in any of the categories', () => { + it('should create actions to add categories list with no medium and description in any of the categories', () => { const categories = [ { id: 1, name: 'Category' }, { id: 2, name: 'Category' }, @@ -547,8 +632,8 @@ describe('categories actions', () => { { type: types.ADD_CATEGORIES, payload: [ - { id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, - { id: 2, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, + { id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, + { id: 2, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, ], }, ]; @@ -557,10 +642,10 @@ describe('categories actions', () => { store.dispatch(actions.addCategories(categories)); expect(store.getActions()).toEqual(expectedActions); }); - it('should create actions to add categories list', () => { + it('should create actions to add categories list with some have medium and description in any of the categories', () => { const medium = { id: 4, name: 'mediumm' }; const categories = [ - { id: 1, name: 'Category' }, + { id: 1, name: 'Category', description: { html: "hello
", json: { "hello": "test" } } }, { id: 2, name: 'Category', medium: medium }, ]; @@ -572,8 +657,8 @@ describe('categories actions', () => { { type: types.ADD_CATEGORIES, payload: [ - { id: 1, name: 'Category', medium: undefined, description: { "html": undefined, "json": undefined, } }, - { id: 2, name: 'Category', medium: 4, description: { "html": undefined, "json": undefined, } }, + { id: 1, name: 'Category', medium: undefined, description: { html: "hello
", json: { "hello": "test" } } }, + { id: 2, name: 'Category', medium: 4, description: { "html": undefined, "json": undefined, } }, ], }, ]; @@ -582,6 +667,59 @@ describe('categories actions', () => { store.dispatch(actions.addCategories(categories)); expect(store.getActions()).toEqual(expectedActions); }); + it('should create actions to add categories list with all have description(modified) in any of the categories', () => { + const medium = { id: 4, name: 'mediumm' }; + const categories = [ + { id: 1, name: 'Category', description: { html: "hello
", json: { "hello": "test" } } }, + { id: 2, name: 'Category', medium: medium, description: { html: "hello
", json: { "hello": "test" } } }, + ]; + + const expectedActions = [ + { + type: ADD_MEDIA, + payload: [medium], + }, + { + type: types.ADD_CATEGORIES, + payload: [ + { id: 1, name: 'Category', medium: undefined, description: { html: "hello
", json: { "hello": "test" } } }, + { id: 2, name: 'Category', medium: 4, description: { html: "hello
", json: { "hello": "test" } } }, + ], + }, + ]; + + const store = mockStore({ initialState }); + store.dispatch(actions.addCategories(categories)); + expect(store.getActions()).toEqual(expectedActions); + }); + it('should create actions to add categories list with all have medium and description(unmodified) in any of the categories', () => { + const medium = { id: 4, name: 'medium1' }; + const description = { "hello": "test" } + const description_html = "hello
" + const categories = [ + { id: 1, name: 'Category',medium, description, description_html }, + { id: 2, name: 'Category2', description, description_html }, + ]; + + const expectedActions = [ + { + type: ADD_MEDIA, + payload: [medium], + }, + { + type: types.ADD_CATEGORIES, + payload: [ + { id: 1, name: 'Category', medium: 4, description: { html: "hello
", json: { "hello": "test" } } }, + { id: 2, name: 'Category2', medium: undefined, description: { html: "hello
", json: { "hello": "test" } } }, + ], + }, + ]; + + const store = mockStore({ initialState }); + store.dispatch(actions.addCategories(categories)); + expect(store.getActions()).toEqual(expectedActions); + }); + it('should create actions to add empty categories list', () => { const categories = []; diff --git a/studio/src/__tests__/actions/podcasts.js b/studio/src/__tests__/actions/podcasts.js index 02e3b7b96..71925472b 100644 --- a/studio/src/__tests__/actions/podcasts.js +++ b/studio/src/__tests__/actions/podcasts.js @@ -325,8 +325,10 @@ describe('Podcast actions', () => { }, { type: types.ADD_PODCAST, - payload: { id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1], - description: { json: { "hello": "world" }, html: "hello world
" } }, + payload: { + id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1], + description: { json: { "hello": "world" }, html: "hello world
" } + }, }, { type: ADD_NOTIFICATION, @@ -349,6 +351,110 @@ describe('Podcast actions', () => { .then(() => expect(store.getActions()).toEqual(expectedActions)); expect(axios.put).toHaveBeenCalledWith(types.PODCASTS_API + '/1', podcast); }); + it('should create actions to update podcast success with description not modified', () => { + const podcast = { + id: 1, + title: 'Podcast', + episodes: [{ id: 1 }], + categories: [{ id: 1, medium: { id: 1 }, description: { "hello": "world" }, description_html: "hello world
" }], + description: { "hello": "world" }, description_html: "hello world
" + }; + const resp = { data: podcast }; + axios.put.mockResolvedValue(resp); `` + + const expectedActions = [ + { + type: types.SET_PODCASTS_LOADING, + payload: true, + }, + { + type: ADD_MEDIA, + payload: [{ id: 1 }], + }, + { + type: ADD_CATEGORIES, + payload: [{ id: 1, medium: 1, description: { json: { "hello": "world" }, html: "hello world
" } }], + }, + { + type: types.ADD_PODCAST, + payload: { + id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1], + description: { json: { "hello": "world" }, html: "hello world
" } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Podcast updated', + time: Date.now(), + }, + }, + { + type: types.SET_PODCASTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePodcast(podcast)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.PODCASTS_API + '/1', podcast); + }); + it('should create actions to update podcast success without description', () => { + const podcast = { + id: 1, + title: 'Podcast', + episodes: [{ id: 1 }], + categories: [{ id: 1, medium: { id: 1 }, description: { "hello": "world" }, description_html: "hello world
" }], + }; + const resp = { data: podcast }; + axios.put.mockResolvedValue(resp); `` + + const expectedActions = [ + { + type: types.SET_PODCASTS_LOADING, + payload: true, + }, + { + type: ADD_MEDIA, + payload: [{ id: 1 }], + }, + { + type: ADD_CATEGORIES, + payload: [{ id: 1, medium: 1, description: { json: { "hello": "world" }, html: "hello world
" } }], + }, + { + type: types.ADD_PODCAST, + payload: { + id: 1, title: 'Podcast', episodes: [{ id: 1 }], categories: [1], + description: { json: undefined, html: undefined } + }, + }, + { + type: ADD_NOTIFICATION, + payload: { + type: 'success', + title: 'Success', + message: 'Podcast updated', + time: Date.now(), + }, + }, + { + type: types.SET_PODCASTS_LOADING, + payload: false, + }, + ]; + + const store = mockStore({ initialState }); + store + .dispatch(actions.updatePodcast(podcast)) + .then(() => expect(store.getActions()).toEqual(expectedActions)); + expect(axios.put).toHaveBeenCalledWith(types.PODCASTS_API + '/1', podcast); + }); + it('should create actions to update podcast failure', () => { const podcast = { id: 1, title: 'Podcast' }; const errorMessage = 'Failed to update podcast'; diff --git a/studio/src/actions/categories.js b/studio/src/actions/categories.js index 03ab7f587..6884168bf 100644 --- a/studio/src/actions/categories.js +++ b/studio/src/actions/categories.js @@ -164,7 +164,6 @@ export const addCategories = (categories) => { }; delete category.description_html } - category.description_html && delete category.description_html; return { ...category, medium: category.medium?.id }; }), ), diff --git a/studio/src/actions/podcasts.js b/studio/src/actions/podcasts.js index 7e3c102ca..95947a17d 100644 --- a/studio/src/actions/podcasts.js +++ b/studio/src/actions/podcasts.js @@ -126,12 +126,11 @@ export const updatePodcast = (data) => { .then((response) => { let podcast = response.data; if ((!podcast.description) - || (typeof podcast.description !== 'object' && podcast.hasOwnProperty('description_html')) + || (podcast.hasOwnProperty('description_html')) || (!podcast.description.hasOwnProperty('json') && !podcast.description.hasOwnProperty('html'))) { podcast.description = { json: podcast.description, html: podcast.description_html }; delete podcast.description_html } - // console.log(podcast) dispatch(addCategories(response.data.categories)); dispatch( getPodcastByID({ From 8a63df942fbacdc0fe72cb9d1f561eb296b362a0 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> Date: Thu, 23 Mar 2023 11:14:39 +0000 Subject: [PATCH 18/18] added required changes --- .gitignore | 4 +--- docker-compose.yml | 11 +++-------- studio/src/__tests__/reducers/index.js | 5 +++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 06ad708d3..67f4ef9fe 100644 --- a/.gitignore +++ b/.gitignore @@ -149,7 +149,7 @@ fabric.properties *.test # Output of the go coverage tool, specifically when used with LiteIDE -*.out +#*.out # Dependency directories (remove the comment below to include it) # vendor/ @@ -187,5 +187,3 @@ server/server dist/ *.sqlite - -volumes/postgres/ diff --git a/docker-compose.yml b/docker-compose.yml index 19a22cf63..2a2810d13 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - "5432:5432" volumes: - ./pg-init-scripts:/docker-entrypoint-initdb.d - - ./volumes/postgres:/var/lib/postgresql/data/ + - ~/factly/dega/postgresql:/var/lib/postgresql/data/ environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres @@ -316,12 +316,7 @@ services: - KAVACH_ENABLE_IMGPROXY=false - KAVACH_DYNAMIC_EMAIL_ENABLED=true - KAVACH_BUCKET_NAME=login.factly.in - entrypoint: - [ - "/bin/sh", - "-c", - "/app/kavach-server migrate && /app/kavach-server create-super-org", - ] + entrypoint: ["/bin/sh", "-c" , "/app/kavach-server migrate && /app/kavach-server create-super-org"] networks: - dega @@ -484,7 +479,7 @@ services: volumes: - type: bind source: ./api - target: /appendonly + target: /app restart: unless-stopped networks: - dega diff --git a/studio/src/__tests__/reducers/index.js b/studio/src/__tests__/reducers/index.js index 63dcf3b4f..a78bbb558 100644 --- a/studio/src/__tests__/reducers/index.js +++ b/studio/src/__tests__/reducers/index.js @@ -183,6 +183,11 @@ const initialState = { details: {}, loading: true, }, + webhooklogs: { + req: [], + details: {}, + loading: true, + }, profile: { details: {}, loading: true,