Skip to content

Commit

Permalink
add tests for inferring date type from string and array of strings, m…
Browse files Browse the repository at this point in the history
…ove date related test to seperate date test suite
  • Loading branch information
pieh committed Jan 27, 2018
1 parent bba3dad commit b6c0664
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`GraphQL type inferance Handles dates Date type inference 1`] = `
Object {
"data": Object {
"listNode": Array [
Object {
"dateObject": "2012-11-05T00:00:00.000Z",
},
Object {
"dateObject": "2012-11-05T00:00:00.000Z",
},
],
},
}
`;

exports[`GraphQL type inferance Infers graphql type from array of nodes 1`] = `
Object {
"data": Object {
Expand Down Expand Up @@ -115,18 +130,3 @@ Object {
},
}
`;

exports[`GraphQL type inferance handles date objects 1`] = `
Object {
"data": Object {
"listNode": Array [
Object {
"dateObject": "2012-11-05T00:00:00.000Z",
},
Object {
"dateObject": "2012-11-05T00:00:00.000Z",
},
],
},
}
`;
74 changes: 51 additions & 23 deletions packages/gatsby/src/schema/__tests__/infer-graphql-type-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,6 @@ describe(`GraphQL type inferance`, () => {
expect(result.data.listNode[0].number).toEqual(1.1)
})

it(`handles integer with valid date format`, async () => {
let result = await queryResult(
[{ number: 2018 }, { number: 1987 }],
`
number
`
)
expect(result.data.listNode[0].number).toEqual(2018)
})

it(`handles date objects`, async () => {
let result = await queryResult(
[
{ dateObject: new Date(Date.UTC(2012, 10, 5)) },
{ dateObject: new Date(Date.UTC(2012, 10, 5)) },
],
`
dateObject
`
)
expect(result).toMatchSnapshot()
})

it(`filters out empty objects`, async () => {
let result = await queryResult(
[{ foo: {}, bar: `baz` }],
Expand Down Expand Up @@ -211,6 +188,57 @@ describe(`GraphQL type inferance`, () => {
expect(Object.keys(fields.foo.type.getFields())).toHaveLength(4)
})

describe(`Handles dates`, () => {
it(`Handles integer with valid date format`, async () => {
let result = await queryResult(
[{ number: 2018 }, { number: 1987 }],
`
number
`
)
expect(result.data.listNode[0].number).toEqual(2018)
})

it(`Date type inference`, async () => {
let result = await queryResult(
[
{ dateObject: new Date(Date.UTC(2012, 10, 5)) },
{ dateObject: new Date(Date.UTC(2012, 10, 5)) },
],
`
dateObject
`
)
expect(result).toMatchSnapshot()
})

it(`Infers from date strings`, async () => {
let result = await queryResult(
[{ date: `1012-11-01` }],
`
date(formatString:"DD.MM.YYYY")
`
)

expect(result.errors).not.toBeDefined()
expect(result.data.listNode[0].date).toEqual(`01.11.1012`)
})

it(`Infers from arrays of date strings`, async () => {
let result = await queryResult(
[{ date: [`1012-11-01`, `10390203`] }],
`
date(formatString:"DD.MM.YYYY")
`
)

expect(result.errors).not.toBeDefined()
expect(result.data.listNode[0].date.length).toEqual(2)
expect(result.data.listNode[0].date[0]).toEqual(`01.11.1012`)
expect(result.data.listNode[0].date[1]).toEqual(`03.02.1039`)
})
})

xdescribe(`Linked inference from config mappings`)

describe(`Linked inference from file URIs`, () => {
Expand Down

0 comments on commit b6c0664

Please sign in to comment.