Skip to content

Commit

Permalink
test: adopt @cap-js/sqlite (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-vogel authored Feb 23, 2024
1 parent da6f1e2 commit 9ed44e0
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 35 deletions.
3 changes: 2 additions & 1 deletion lib/resolvers/crud/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = async ({ req, res }, service, entity, selection) => {
const args = selection.arguments

let query = SELECT.from(entity)
query.columns(astToColumns(entity, selection.selectionSet.selections, true))
const columns = astToColumns(entity, selection.selectionSet.selections, true)
if (columns.length) query.columns(columns)

const filter = getArgumentByName(args, ARGS.filter)
if (filter) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"express": "^4.17.1",
"jest": "^29.3.1",
"semver": "^7.4.0",
"sqlite3": "^5.0.2"
"@cap-js/sqlite": "^1"
}
}
3 changes: 3 additions & 0 deletions test/resources/annotations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"dependencies": {
"@cap-js/graphql": "*"
},
"devDependencies": {
"@cap-js/sqlite": "*"
},
"cds": {
"protocols": {
"graphql": {
Expand Down
4 changes: 4 additions & 0 deletions test/resources/bookshop-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"dependencies": {
"@cap-js/graphql": "*"
},
"devDependencies": {
"@cap-js/sqlite": "*"
},
"cds": {
"requires": {
"db": {
"kind": "sqlite",
"impl": "@cap-js/sqlite",
"credentials": {
"database": ":memory:"
}
Expand Down
3 changes: 3 additions & 0 deletions test/resources/bookshop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"@sap/cds": ">=5.9",
"express": "^4.17.1"
},
"devDependencies": {
"@cap-js/sqlite": "*"
},
"scripts": {
"genres": "cds serve test/genres.cds",
"start": "cds run",
Expand Down
3 changes: 3 additions & 0 deletions test/resources/cds.Request/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {
"@cap-js/graphql": "*"
},
"devDependencies": {
"@cap-js/sqlite": "*"
}
}
3 changes: 3 additions & 0 deletions test/resources/concurrency/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {
"@cap-js/graphql": "*"
},
"devDependencies": {
"@cap-js/sqlite": "*"
}
}
3 changes: 3 additions & 0 deletions test/resources/custom-error-formatter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"dependencies": {
"@cap-js/graphql": "*"
},
"devDependencies": {
"@cap-js/sqlite": "*"
},
"cds": {
"protocols": {
"graphql": {
Expand Down
5 changes: 5 additions & 0 deletions test/resources/custom-handlers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"@cap-js/sqlite": "*"
}
}
3 changes: 3 additions & 0 deletions test/resources/edge-cases/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {
"@cap-js/graphql": "*"
},
"devDependencies": {
"@cap-js/sqlite": "*"
}
}
3 changes: 3 additions & 0 deletions test/resources/error-handling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"dependencies": {
"@cap-js/graphql": "*"
},
"devDependencies": {
"@cap-js/sqlite": "*"
},
"cds": {
"requires": {
"db": {
Expand Down
5 changes: 5 additions & 0 deletions test/resources/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@cap-js/sqlite": "*"
}
}
6 changes: 3 additions & 3 deletions test/tests/queries/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe('graphql - filter', () => {
const query = gql`
{
AdminService {
Books(filter: [{ ID: { in: [201, 251] } }, { title: { contains: "cat" } }]) {
Books(filter: [{ ID: { in: [201, 251] } }, { title: { contains: "Cat" } }]) {
nodes {
ID
title
Expand Down Expand Up @@ -468,10 +468,10 @@ describe('graphql - filter', () => {
Books(
filter: [
{
title: [{ startswith: "the", endswith: "raven" }, { contains: "height" }]
title: [{ startswith: "The", endswith: "Raven" }, { contains: "Height" }]
ID: [{ eq: 201 }, { eq: 251 }]
}
{ title: { contains: "cat" } }
{ title: { contains: "Cat" } }
]
) {
nodes {
Expand Down
61 changes: 41 additions & 20 deletions test/tests/queries/paging-offset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,27 @@ describe('graphql - offset-based paging', () => {
}
`
const data = {
AdminServiceBasic: {
Authors: null
AdminService: {
Authors: [
{
name: 'Edgar Allen Poe',
books: [
// Edgar Allen Poe has 2 books, but only 1 requested.
{
title: 'Eleonora'
}
]
},
{
name: 'Richard Carpenter',
books: []
}
]
}
}
const errors = [
{
locations: [{ column: 13, line: 4 }],
message: 'Pagination is not supported in expand',
path: ['AdminServiceBasic', 'Authors']
}
]

const response = await POST('/graphql', { query })
expect(response.data).toEqual({ data, errors })
expect(response.data).toEqual({ data })
})
})

Expand Down Expand Up @@ -139,19 +147,32 @@ describe('graphql - offset-based paging', () => {
`
const data = {
AdminService: {
Authors: null
Authors: {
nodes: [
{
name: 'Edgar Allen Poe',
books: {
// Edgar Allen Poe has 2 books, but only 1 requested.
nodes: [
{
title: 'Eleonora'
}
]
}
},
{
name: 'Richard Carpenter',
books: {
nodes: []
}
}
]
}
}
}
const errors = [
{
locations: [{ column: 13, line: 4 }],
message: 'Pagination is not supported in expand',
path: ['AdminService', 'Authors'],
extensions: expect.any(Object)
}
]

const response = await POST('/graphql', { query })
expect(response.data).toEqual({ data, errors })
expect(response.data).toEqual({ data })
})
})
})
35 changes: 25 additions & 10 deletions test/tests/queries/totalCount.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,34 @@ describe('graphql - queries with totalCount', () => {
`
const data = {
AdminService: {
Authors: null
Authors: {
totalCount: 4,
nodes: [
{
name: 'Edgar Allen Poe',
books: {
totalCount: null, // REVISIT: expected 2
nodes: [
{
title: 'Eleonora'
}
]
}
},
{
name: 'Richard Carpenter',
books: {
totalCount: null, // REVISIT: expected 0
nodes: []
}
}
]
}
}
}
const errors = [
{
locations: [{ column: 11, line: 4 }],
message: 'Pagination is not supported in expand',
path: ['AdminService', 'Authors'],
extensions: expect.any(Object)
}
]

const response = await POST('/graphql', { query })
expect(response.data).toEqual({ data, errors })
expect(response.data).toEqual({ data })
})

test('query with aliases on totalCount on nested fields', async () => {
Expand Down

0 comments on commit 9ed44e0

Please sign in to comment.