Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from redbadger/multiday-events
Browse files Browse the repository at this point in the history
Event end date sanitation
  • Loading branch information
AndrewBestbier authored Jul 13, 2016
2 parents cf29eec + ebfab67 commit 6e7d684
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export function sanitizeEventAndNews(item, type) {
strapline: get(`${type}.strapline`),
datetime: get(`${type}.timestamp`),
startDateTime: get(`${type}.timestamp`),
endDateTime: get(`${type}.timestampEnd`),
endDateTime: pathOr(get(`${type}.timestamp`),
['data', `${type}.timestampEnd`, 'value'], item),
internalLinks: mapLinkList(get(`${type}.internalLinks`)),
externalLinks: mapLinkList(get(`${type}.externalLinks`)),
body: get(`${type}.body`) || [],
Expand Down
11 changes: 11 additions & 0 deletions lib/fetch.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import PrismicMock from '../test/mocks/prismic';
import * as prismicEventResponse from
'../test/fixtures/event-prismic-response.json';

import {
sanitizeEventAndNews,
Expand Down Expand Up @@ -85,8 +87,17 @@ describe('Data sanitation', () => {

expect(sanitizeEventAndNews(event)).to.deep.equal(emptyResponse);
});


it('should copy start datetime to end datetime when end datetime is empty', () => {
const response = sanitizeEventAndNews(prismicEventResponse, 'event');

expect(response.startDateTime).to.deep.equal(response.endDateTime);
expect(response.endDateTime).to.equal('2016-07-27T23:00:00+0000');
});
});


describe('sanitizeCommunity', () => {
it('converts the raw json provided by prismic to be readable by graphql', () => {
const rawData = {
Expand Down
2 changes: 1 addition & 1 deletion lib/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const mapDateTime = fieldName => doc => {
iso: timestamp,
date: dateFns.format(d, 'DD'),
month: dateFns.format(d, 'MM'),
monthSym: dateFns.format(d, 'MMM'),
monthSym: dateFns.format(d, 'MMMM'),
year: dateFns.format(d, 'YYYY'),
};
};
Expand Down
2 changes: 1 addition & 1 deletion lib/resolvers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Resolvers', () => {
iso: data.datetime,
date: '08',
month: '06',
monthSym: 'Jun',
monthSym: 'June',
year: '2016',
});
});
Expand Down
131 changes: 131 additions & 0 deletions test/fixtures/event-prismic-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"id": "V3-PjyMAAF0n2y3Q",
"uid": "react-london-july-meetup",
"type": "event",
"href": "https://rb-website-stage.prismic.io/api/documents/search?ref=V4Y7ciMAAICj9eD-&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22V3-PjyMAAF0n2y3Q%22%29+%5D%5D",
"tags": [],
"slug": "react-london-july-meetup",
"slugs": [
"react-london-july-meetup"
],
"data": {
"event.title": {
"type": "Text",
"value": "React London July Meetup"
},
"event.strapline": {
"type": "Text",
"value": "Awesome meetup"
},
"event.body": {
"type": "StructuredText",
"value": [
{
"type": "paragraph",
"text": "With description",
"spans": []
}
]
},
"event.timestamp": {
"type": "Timestamp",
"value": "2016-07-27T23:00:00+0000"
},
"event.address": {
"type": "Text",
"value": "Skills Matter, CodeNode, 10 South Place, London EC2M 7EB"
},
"event.talks": {
"type": "Group",
"value": [
{
"data": {
"type": "Link.document",
"value": {
"document": {
"id": "V3-t-SMAALE426eq",
"type": "talk",
"tags": [],
"slug": "graphql-for-beginners",
"uid": "GraphQL for beginners"
},
"isBroken": false
}
}
}
]
}
},
"fragments": {
"event.title": {
"value": "React London July Meetup"
},
"event.strapline": {
"value": "Awesome meetup"
},
"event.body": {
"blocks": [
{
"type": "paragraph",
"text": "With description",
"spans": []
}
]
},
"event.timestamp": {
"value": "2016-07-27T23:00:00.000Z"
},
"event.address": {
"value": "Skills Matter, CodeNode, 10 South Place, London EC2M 7EB"
},
"event.talks": {
"value": [
{
"data": {
"data": {
"type": "Link.document",
"value": {
"document": {
"id": "V3-t-SMAALE426eq",
"type": "talk",
"tags": [],
"slug": "graphql-for-beginners",
"uid": "GraphQL for beginners"
},
"isBroken": false
}
}
},
"fragments": {
"data": {
"value": {
"document": {
"id": "V3-t-SMAALE426eq",
"type": "talk",
"tags": [],
"slug": "graphql-for-beginners",
"uid": "GraphQL for beginners"
},
"isBroken": false
},
"document": {
"id": "V3-t-SMAALE426eq",
"type": "talk",
"tags": [],
"slug": "graphql-for-beginners",
"uid": "GraphQL for beginners"
},
"id": "V3-t-SMAALE426eq",
"uid": "GraphQL for beginners",
"tags": [],
"slug": "graphql-for-beginners",
"type": "talk",
"fragments": {},
"isBroken": false
}
}
}
]
}
}
}
2 changes: 1 addition & 1 deletion test/fixtures/news-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"iso": "2016-02-02T12:00:00+0000",
"date": "02",
"month": "02",
"monthSym": "Feb",
"monthSym": "February",
"year": "2016"
},
"strapline": "Red Badger CEO Cain Ullah explains how he and the other Founders learned from their own experience to build incentives for Red Badger that go beyond the impersonal ‘reward’ of financial bonuses",
Expand Down

0 comments on commit 6e7d684

Please sign in to comment.