Skip to content

Commit

Permalink
Add test for in operator with single value
Browse files Browse the repository at this point in the history
  • Loading branch information
schwma committed Jan 8, 2024
1 parent 6e29640 commit 5cc3463
Showing 1 changed file with 46 additions and 22 deletions.
68 changes: 46 additions & 22 deletions test/tests/queries/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ describe('graphql - filter', () => {
expect(response.data).toEqual({ data })
})

test('query with simple filter wrapped as lists', async () => {
test('query with filter with in operator with single value', async () => {
const query = gql`
{
AdminService {
Books(filter: [{ ID: [{ eq: 201 }] }]) {
Books(filter: { ID: { in: 201 } }) {
nodes {
ID
title
Expand All @@ -277,18 +277,20 @@ describe('graphql - filter', () => {
`
const data = {
AdminService: {
Books: { nodes: [{ ID: 201, title: 'Wuthering Heights' }] }
Books: {
nodes: [{ ID: 201, title: 'Wuthering Heights' }]
}
}
}
const response = await POST('/graphql', { query })
expect(response.data).toEqual({ data })
})

test('query with filter joined by AND on the same field', async () => {
test('query with filter with in operator with multiple values', async () => {
const query = gql`
{
AdminService {
Books(filter: { ID: { gt: 250, lt: 260 } }) {
Books(filter: [{ ID: { in: [201, 251] } }, { title: { contains: "cat" } }]) {
nodes {
ID
title
Expand All @@ -301,8 +303,9 @@ describe('graphql - filter', () => {
AdminService: {
Books: {
nodes: [
{ ID: 201, title: 'Wuthering Heights' },
{ ID: 251, title: 'The Raven' },
{ ID: 252, title: 'Eleonora' }
{ ID: 271, title: 'Catweazle' }
]
}
}
Expand All @@ -311,11 +314,11 @@ describe('graphql - filter', () => {
expect(response.data).toEqual({ data })
})

test('query with filter joined by AND on the same field with the same operator', async () => {
test('query with simple filter wrapped as lists', async () => {
const query = gql`
{
AdminService {
Books(filter: { title: { contains: ["Wuthering", "Heights"] } }) {
Books(filter: [{ ID: [{ eq: 201 }] }]) {
nodes {
ID
title
Expand All @@ -333,11 +336,11 @@ describe('graphql - filter', () => {
expect(response.data).toEqual({ data })
})

test('query with filter joined by AND on different fields', async () => {
test('query with filter joined by AND on the same field', async () => {
const query = gql`
{
AdminService {
Books(filter: { ID: { eq: 251 }, title: { eq: "The Raven" } }) {
Books(filter: { ID: { gt: 250, lt: 260 } }) {
nodes {
ID
title
Expand All @@ -348,18 +351,23 @@ describe('graphql - filter', () => {
`
const data = {
AdminService: {
Books: { nodes: [{ ID: 251, title: 'The Raven' }] }
Books: {
nodes: [
{ ID: 251, title: 'The Raven' },
{ ID: 252, title: 'Eleonora' }
]
}
}
}
const response = await POST('/graphql', { query })
expect(response.data).toEqual({ data })
})

test('query with filter joined by OR on the same field', async () => {
test('query with filter joined by AND on the same field with the same operator', async () => {
const query = gql`
{
AdminService {
Books(filter: { ID: [{ eq: 201 }, { eq: 251 }] }) {
Books(filter: { title: { contains: ["Wuthering", "Heights"] } }) {
nodes {
ID
title
Expand All @@ -370,23 +378,40 @@ describe('graphql - filter', () => {
`
const data = {
AdminService: {
Books: {
nodes: [
{ ID: 201, title: 'Wuthering Heights' },
{ ID: 251, title: 'The Raven' }
]
Books: { nodes: [{ ID: 201, title: 'Wuthering Heights' }] }
}
}
const response = await POST('/graphql', { query })
expect(response.data).toEqual({ data })
})

test('query with filter joined by AND on different fields', async () => {
const query = gql`
{
AdminService {
Books(filter: { ID: { eq: 251 }, title: { eq: "The Raven" } }) {
nodes {
ID
title
}
}
}
}
`
const data = {
AdminService: {
Books: { nodes: [{ ID: 251, title: 'The Raven' }] }
}
}
const response = await POST('/graphql', { query })
expect(response.data).toEqual({ data })
})

test('query with filter with in operator', async () => {
test('query with filter joined by OR on the same field', async () => {
const query = gql`
{
AdminService {
Books(filter: [{ ID: { in: [201, 251] } }, { title: { contains: "cat" } }]) {
Books(filter: { ID: [{ eq: 201 }, { eq: 251 }] }) {
nodes {
ID
title
Expand All @@ -400,8 +425,7 @@ describe('graphql - filter', () => {
Books: {
nodes: [
{ ID: 201, title: 'Wuthering Heights' },
{ ID: 251, title: 'The Raven' },
{ ID: 271, title: 'Catweazle' }
{ ID: 251, title: 'The Raven' }
]
}
}
Expand Down

0 comments on commit 5cc3463

Please sign in to comment.