Skip to content

Added knex integration tests for dates inc relative#29

Open
ErisDS wants to merge 2 commits intoTryGhost:mainfrom
ErisDS:dates
Open

Added knex integration tests for dates inc relative#29
ErisDS wants to merge 2 commits intoTryGhost:mainfrom
ErisDS:dates

Conversation

@ErisDS
Copy link
Member

@ErisDS ErisDS commented Mar 3, 2022

  • This adds missing test coverage for dates and relative dates, showing this results in correct queries against the db

- This adds missing test coverage for dates and relative dates, showing this results in correct queries against the db
@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

Walkthrough

This pull request adds timestamp support to test fixtures and introduces integration tests for date-based querying functionality. The changes include adding created_at and updated_at timestamp fields to JSON and database fixtures across the Knex and Mingo test suites, updating the database schema migration to include a timestamps column, and adding new test cases that validate querying behavior using various date formats (standard date strings, ISO date strings, and relative date expressions).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Added knex integration tests for dates inc relative' accurately describes the main changes, which include adding integration tests for date and relative date querying.
Description check ✅ Passed The description relates to the changeset by explaining the purpose of adding test coverage for dates and relative dates with integration tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/nql/test/integration/nql_knex.test.js`:
- Around line 71-78: Tests assert result[0..n] without a deterministic sort;
update the query chains (the call starting with query.querySQL(knex('posts')))
to include an explicit .orderBy('title') before .select() (and do the same for
the other two test blocks referenced) so the row order is deterministic across
DB engines and the index-based assertions remain stable.

In `@packages/nql/test/integration/nql_mingo.test.js`:
- Around line 450-451: Remove the two debug statements causing lint errors:
delete the lines containing console.log(new Date().toISOString()) and
console.log(new Date()) from the test (or replace them with a proper test
assertion or a test logger call that complies with the project's linting),
ensuring the test no longer uses console.* so it passes the no-console rule.
- Line 417: Replace the exclusive Mocha suite call describe.only in the test
file (the "Dates" suite) with a normal describe so the suite doesn't block other
tests, and remove the stray console.log statements inside that "Dates" suite
(the console.log calls around the date tests) to satisfy lint rules and avoid
noisy test output.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89b5ab3 and 459416e.

📒 Files selected for processing (5)
  • packages/nql/test/integration/knex/fixtures/base.json
  • packages/nql/test/integration/knex/schema.js
  • packages/nql/test/integration/mingo/simple.json
  • packages/nql/test/integration/nql_knex.test.js
  • packages/nql/test/integration/nql_mingo.test.js

Comment on lines +71 to +78
return query
.querySQL(knex('posts'))
.select()
.then((result) => {
result.should.be.an.Array().with.lengthOf(2);
result[0].title.should.eql('Be Our Guest');
result[1].title.should.eql('He\'s a Tramp');
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Make row ordering explicit before index-based assertions.

These tests assert result[0..n] but the query has no explicit sort, so ordering is nondeterministic and may flake across DB engines.

Suggested fix
         return query
-            .querySQL(knex('posts'))
+            .querySQL(knex('posts').orderBy('id', 'asc'))
             .select()
             .then((result) => {
                 result.should.be.an.Array().with.lengthOf(2);
                 result[0].title.should.eql('Be Our Guest');
                 result[1].title.should.eql('He\'s a Tramp');
             });
@@
         return query
-            .querySQL(knex('posts'))
+            .querySQL(knex('posts').orderBy('id', 'asc'))
             .select()
             .then((result) => {
                 result.should.be.an.Array().with.lengthOf(2);
                 result[0].title.should.eql('Be Our Guest');
                 result[1].title.should.eql('He\'s a Tramp');
             });
@@
         return query
-            .querySQL(knex('posts'))
+            .querySQL(knex('posts').orderBy('id', 'asc'))
             .select()
             .then((result) => {
                 result.should.be.an.Array().with.lengthOf(4);
                 result[0].title.should.eql('When She Loved Me');
                 result[1].title.should.eql('Circle of Life');

Also applies to: 85-92, 100-109

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nql/test/integration/nql_knex.test.js` around lines 71 - 78, Tests
assert result[0..n] without a deterministic sort; update the query chains (the
call starting with query.querySQL(knex('posts'))) to include an explicit
.orderBy('title') before .select() (and do the same for the other two test
blocks referenced) so the row order is deterministic across DB engines and the
index-based assertions remain stable.

});
});

describe.only('Dates', function () {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

fd -t f "nql_mingo.test.js" | head -5

Repository: TryGhost/NQL

Length of output: 103


🏁 Script executed:

# Check if the file exists and read the relevant section
wc -l packages/nql/test/integration/nql_mingo.test.js

Repository: TryGhost/NQL

Length of output: 107


🏁 Script executed:

# Read the specific lines around the describe.only
sed -n '410,460p' packages/nql/test/integration/nql_mingo.test.js

Repository: TryGhost/NQL

Length of output: 2589


Remove the exclusive Mocha suite before merge.

describe.only at line 417 will skip all other integration tests and mask regressions. Additionally, remove the console.log statements at lines 450–451 which violate lint rules.

Suggested fix
-    describe.only('Dates', function () {
+    describe('Dates', function () {
-            console.log(new Date().toISOString());
-            console.log(new Date());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe.only('Dates', function () {
describe('Dates', function () {
🧰 Tools
🪛 ESLint

[error] 417-417: Unexpected exclusive mocha test.

(ghost/mocha/no-exclusive-tests)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nql/test/integration/nql_mingo.test.js` at line 417, Replace the
exclusive Mocha suite call describe.only in the test file (the "Dates" suite)
with a normal describe so the suite doesn't block other tests, and remove the
stray console.log statements inside that "Dates" suite (the console.log calls
around the date tests) to satisfy lint rules and avoid noisy test output.

Comment on lines +450 to +451
console.log(new Date().toISOString());
console.log(new Date());
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Drop debug console output from tests.

Line 450 and Line 451 introduce console.log noise and fail linting (no-console).

Suggested fix
-            console.log(new Date().toISOString());
-            console.log(new Date());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log(new Date().toISOString());
console.log(new Date());
🧰 Tools
🪛 ESLint

[error] 450-450: Unexpected console statement.

(no-console)


[error] 451-451: Unexpected console statement.

(no-console)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nql/test/integration/nql_mingo.test.js` around lines 450 - 451,
Remove the two debug statements causing lint errors: delete the lines containing
console.log(new Date().toISOString()) and console.log(new Date()) from the test
(or replace them with a proper test assertion or a test logger call that
complies with the project's linting), ensuring the test no longer uses console.*
so it passes the no-console rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant