Skip to content

Commit

Permalink
Implement and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieAHB committed Jun 18, 2019
1 parent e1cf1a7 commit 7b499f4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
8 changes: 6 additions & 2 deletions client-v2/src/actions/Collections.ts
@@ -1,7 +1,6 @@
import { batchActions } from 'redux-batched-actions';
import {
getArticlesBatched,
updateCollection as updateCollectionFromApi,
discardDraftChangesToCollection as discardDraftChangesToCollectionApi,
fetchVisibleArticles,
fetchLastPressed as fetchLastPressedApi,
Expand Down Expand Up @@ -71,6 +70,7 @@ import { State } from 'types/State';
import { events } from 'services/GA';
import { collectionParamsSelector } from 'selectors/collectionSelectors';
import { fetchCollectionsStrategy } from 'strategies/fetch-collection';
import { updateCollectionStrategy } from 'strategies/update-collection';

const articlesInCollection = createAllArticlesInCollectionSelector();
const collectionsInOpenFrontsSelector = createCollectionsInOpenFrontsSelector();
Expand Down Expand Up @@ -262,7 +262,11 @@ function updateCollection(collection: Collection): ThunkResult<Promise<void>> {
getState(),
collection.id
);
await updateCollectionFromApi(collection.id, denormalisedCollection);
await updateCollectionStrategy(
getState(),
collection.id,
denormalisedCollection
);
dispatch(collectionActions.updateSuccess(collection.id));
const visibleArticles = await getVisibleArticles(
collection,
Expand Down
1 change: 1 addition & 0 deletions client-v2/src/actions/__tests__/Persistence.spec.ts
Expand Up @@ -39,6 +39,7 @@ const A4 = {

const init = () => {
const initState = {
path: '/v2/editorial',
shared: {
collections: {
loadingIds: [],
Expand Down
7 changes: 7 additions & 0 deletions client-v2/src/routes/editions.ts
@@ -0,0 +1,7 @@
const api = (path: string) => `/editions-api/${path}`;

const collection = (collectionId: string) => api(`collections/${collectionId}`);
const editionIssue = (editionName: string, issueId: string) =>
api(`editions/${editionName}/issues/${issueId}`);

export { collection, editionIssue };
4 changes: 2 additions & 2 deletions client-v2/src/services/__tests__/faciaApi.spec.ts
Expand Up @@ -63,15 +63,15 @@ describe('faciaApi', () => {
})
});
expect.assertions(1);
return expect(updateCollection('exampleId', collection)).resolves.toEqual(
return expect(updateCollection('exampleId')(collection)).resolves.toEqual(
collection
);
});
it('should reject if the server gives a !2XX response', async () => {
fetchMock.once('/v2Edits', { status: 400 });
expect.assertions(1);
try {
await updateCollection('exampleId', collection);
await updateCollection('exampleId')(collection);
} catch (e) {
expect(e.message).toContain('exampleId');
}
Expand Down
3 changes: 3 additions & 0 deletions client-v2/src/shared/fixtures/shared.ts
Expand Up @@ -547,6 +547,7 @@ const collectionWithSupportingArticles = {
};

const stateWithCollection: any = {
path: '/v2/editorial',
fronts: {
frontsConfig: {
data: {
Expand Down Expand Up @@ -651,6 +652,7 @@ const stateWithCollection: any = {
};

const stateWithCollectionAndSupporting: any = {
path: '/v2/editorial',
shared: {
collections: {
data: {
Expand Down Expand Up @@ -712,6 +714,7 @@ const stateWithCollectionAndSupporting: any = {
};

const stateWithSnaplinksAndArticles: any = {
path: '/v2/editorial',
shared: {
articleFragments: {
'1269c42e-a341-4464-b206-a5731b92fa46': {
Expand Down
4 changes: 2 additions & 2 deletions client-v2/src/strategies/update-collection.ts
Expand Up @@ -16,7 +16,7 @@ const collectionToEditionCollection = (
};
};

const fetchCollectionsStrategy = (
const updateCollectionStrategy = (
state: State,
id: string,
collection: CollectionWithNestedArticles
Expand All @@ -28,4 +28,4 @@ const fetchCollectionsStrategy = (
none: () => null
});

export { fetchCollectionsStrategy };
export { updateCollectionStrategy };

0 comments on commit 7b499f4

Please sign in to comment.