Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adopt @cap-js/sqlite #157

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these added for the plugin detection ?
If that is the reason it would be better to run the test with CDS_CONFIG to allow for testing with not just @cap-js/sqlite.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to introduce those internal flags also for open source modules.
In the meanwhile, I'd hope that there's no need anymore to switch back to the old implementation :)

},
"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 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

})
})

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the totalCount is probably being returned as [email protected]. As defined here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a BLI for us. Seems very "odata'ish" :)

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
Loading