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 #51 from redbadger/editable-event-status
Browse files Browse the repository at this point in the history
Added ticket release date, ticket available and action link to event
  • Loading branch information
asavin authored Jul 28, 2016
2 parents 16c2c13 + 8e55cd3 commit 287d07a
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 13 deletions.
10 changes: 10 additions & 0 deletions lib/event/eventFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLBoolean,
} from 'graphql';
import {
fetchEvent,
Expand Down Expand Up @@ -73,6 +74,15 @@ export const EventType = new GraphQLObjectType({
type: DateTimeType,
resolve: mapDateTime('endDateTime'),
},
ticketReleaseDate: {
type: DateTimeType,
description: 'The date when the event tickets are released.',
resolve: mapDateTime('ticketReleaseDate'),
},
ticketsAvailable: {
type: GraphQLBoolean,
description: 'A boolean to show whether tickets are availiable',
},
schedule: {
type: new GraphQLList(ScheduleItemType),
description: 'An array of schedule items that each have a date and text description',
Expand Down
50 changes: 49 additions & 1 deletion lib/event/eventFields.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,29 @@ describe('Event Queries', () => {
title
slug
strapline
internalLinks {
title
url
type
}
externalLinks {
title
url
type
}
schedule {
datetime
text
}
ticketsAvailable
sponsors {
websiteURL
imageURL
name
}
ticketReleaseDate {
date
}
featureImageFilename
location {
address
Expand All @@ -78,7 +92,6 @@ describe('Event Queries', () => {
`;

const result = await graphql(EventsSchema, query);

expect(result.data).to.deep.equal({
allEvents: [
{
Expand All @@ -94,6 +107,29 @@ describe('Event Queries', () => {
longitude: '-0.08610963821411133',
},
},
externalLinks: [
{
title: 'London Node.js User Group',
type: 'STREAM',
url: 'http://lnug.org/',
},
{
title: 'Attend or track the event on Lanyrd',
url: 'http://lanyrd.com/2013/lnug-july/',
type: 'OTHER',
},
],
internalLinks: [
{
title: 'Who is David?',
url: '/about-us/people/david-wynne',
type: 'OTHER',
},
],
ticketReleaseDate: {
date: '24',
},
ticketsAvailable: false,
schedule: [],
sponsors: [],
},
Expand All @@ -110,6 +146,17 @@ describe('Event Queries', () => {
longitude: '-0.08610963821411133',
},
},
externalLinks: [
{
title: 'For more information please visit the conference page',
url: 'https://www.react-europe.org/#about',
type: 'EVENT',
},
],
internalLinks: [],
ticketReleaseDate: {
date: '24',
},
schedule: [{
datetime: '2016-07-25T23:00:00+0000',
text: 'Doors open for pizza and beers',
Expand All @@ -120,6 +167,7 @@ describe('Event Queries', () => {
datetime: '2016-07-25T23:00:00+0000',
text: 'Various speakers chat',
}],
ticketsAvailable: false,
sponsors: [{
imageURL: 'http://react.london/img/SVG/Badger_Roundel.svg',
websiteURL: 'http://red-badger.com',
Expand Down
4 changes: 4 additions & 0 deletions lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ function makeGetter(json) {
return key => pathOr(null, ['data', key, 'value'], json);
}

// TODO: move to sanitizing layer TBD.
export function reformatLinkList(linkList) {
if (!linkList) return [];
return linkList.map((link) => {
const newLink = {};
newLink.title = link.label;
newLink.url = link.link;
newLink.type = link.type || { value: 'OTHER' };
return newLink;
});
}
Expand All @@ -29,6 +31,8 @@ export function sanitizeEventAndNews(item, type) {
startDateTime: get(`${type}.timestamp`),
endDateTime: pathOr(get(`${type}.timestamp`),
['data', `${type}.timestampEnd`, 'value'], item),
ticketReleaseDate: get(`${type}.ticketReleaseDate`),
ticketsAvailable: get(`${type}.ticketsAvailable`) || false,
internalLinks: reformatLinkList((get(`${type}.internalLinks`))),
externalLinks: reformatLinkList((get(`${type}.externalLinks`))),
body: get(`${type}.body`) || [],
Expand Down
27 changes: 27 additions & 0 deletions lib/fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
sanitizeCommunity,
sanitizeSpeaker,
sanitizeTalk,
reformatLinkList,
} from './fetch';

describe('Fetch', () => {
Expand Down Expand Up @@ -81,6 +82,8 @@ describe('Data sanitation', () => {
datetime: null,
startDateTime: null,
endDateTime: null,
ticketReleaseDate: null,
ticketsAvailable: false,
body: [],
talks: [],
schedule: [],
Expand Down Expand Up @@ -185,4 +188,28 @@ describe('sanitizeTalk', () => {
],
});
});

describe('reformatLinks', () => {
it('returns an array of formatted objects', () => {
const initialList = [
{ label: { value: 'foo' }, link: { value: 'bar.com' }, type: { value: 'STREAM' } },
];
const expectedNewList = [
{ title: { value: 'foo' }, url: { value: 'bar.com' }, type: { value: 'STREAM' } },
];

expect(reformatLinkList(initialList)).to.deep.equal(expectedNewList);
});

it('no type property defaults type to OTHER', () => {
const initialList = [
{ label: { value: 'foo' }, link: { value: 'bar.com' } },
];
const expectedNewList = [
{ title: { value: 'foo' }, url: { value: 'bar.com' }, type: { value: 'OTHER' } },
];

expect(reformatLinkList(initialList)).to.deep.equal(expectedNewList);
});
});
});
4 changes: 4 additions & 0 deletions lib/sharedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,9 @@ export const RelatedLinkType = new GraphQLObjectType({
type: GraphQLString,
description: 'Full URL of the link',
},
type: {
type: GraphQLString,
description: 'Type of the link',
},
},
});
32 changes: 32 additions & 0 deletions prismic/custom-types/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@
"label" : "End date and time"
}
},
"ticketReleaseDate" : {
"type" : "Timestamp",
"config" : {
"label" : "Ticket release date"
}
},
"ticketsAvailable" : {
"type" : "Select",
"fieldset" : "A boolean showing whether the tickets are availiable",
"config" : {
"label" : "Tickets Available",
"options" : [ false, true ]
}
},
"address" : {
"type" : "Text",
"fieldset" : "Event location",
Expand All @@ -73,6 +87,15 @@
"config" : {
"placeholder" : "Link URL"
}
},
"type" : {
"type" : "Select",
"fieldset" : "A type of link",
"config" : {
"label" : "Link Type",
"options" : [ "STREAM", "EVENT" ],
"placeholder" : "OTHER"
}
}
}
}
Expand Down Expand Up @@ -139,6 +162,15 @@
"config" : {
"placeholder" : "Link URL"
}
},
"type" : {
"type" : "Select",
"fieldset" : "A type of link",
"config" : {
"label" : "Link Type",
"options" : [ "STREAM", "EVENT" ],
"placeholder" : "OTHER"
}
}
}
}
Expand Down
52 changes: 40 additions & 12 deletions test/fixtures/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,43 @@
"sponsors": [],
"externalLinks": [
{
"title": "London Node.js User Group",
"url": "http://lnug.org/"
"title": {
"value": "London Node.js User Group"
},
"url": {
"value": "http://lnug.org/"
},
"type": {
"value": "STREAM"
}
},
{
"title": "Attend or track the event on Lanyrd",
"url": "http://lanyrd.com/2013/lnug-july/"
"title": {
"value": "Attend or track the event on Lanyrd"
},
"url": {
"value": "http://lanyrd.com/2013/lnug-july/"
},
"type": {
"value": "OTHER"
}
}
],
"internalLinks": [
{
"title": "Who is David?",
"url": "/about-us/people/david-wynne"
},
{
"title": "Who is Joe?",
"url": "/about-us/people/joe-stanton"
"title": {
"value": "Who is David?"
},
"url": {
"value": "/about-us/people/david-wynne"
},
"type": {
"value": "OTHER"
}
}
],
"ticketReleaseDate": "2013-07-24T12:00:00.000Z",
"ticketsAvailable": false,
"featureImageFilename": "profile_DW_thumb.jpg",
"body": "The Red Badger tech team talk about how Node powered the new BBC Now homepage pilot.",
"datetime": {
Expand All @@ -54,10 +73,19 @@
"featureImageFilename": "react-europe.jpg",
"externalLinks": [
{
"title": "For more information please visit the conference page",
"url": "https://www.react-europe.org/#about"
"title": {
"value": "For more information please visit the conference page"
},
"url": {
"value": "https://www.react-europe.org/#about"
},
"type": {
"value": "EVENT"
}
}
],
"ticketReleaseDate": "2013-07-24T12:00:00.000Z",
"ticketsAvailable": false,
"schedule": [
{
"datetime": {
Expand Down

0 comments on commit 287d07a

Please sign in to comment.