blitz-orm icon indicating copy to clipboard operation
blitz-orm copied to clipboard

Sweep: Add query tests

Open lveillard opened this issue 1 year ago • 1 comments

Details

Context: This repo is an ORM that supports queries for surrealDB and typeDB. The tests are run for both, with the same tests, using the common BQL (Blitz query language) as the input and the output. In the mid part

Todo: Take a deep breath and find out missing query tests for different potential combinations.

As there are roleFields, and two types of linkFields (target: role, and target:relation) we need to test different features on different items.

Context files /home/loic/blitz-orm/tests/mocks/schema.ts //The data follows these rules /home/loic/blitz-orm/tests/mocks/generatedSchema.ts // This is an extended version of that schema, with some precomputed things /home/loic/blitz-orm/tests/surrealdb/mocks/data.surql //This is the original data set, translated to surrealDB /home/loic/blitz-orm/tests/typedb/mocks/data.tql //This is the same data set equivalent, for typeDB Also this is the state machine that runs the BQL to SurrealQL/TypeQL runs it and then transforms the answers back to BQL output: /home/loic/blitz-orm/src/stateMachine/query/machine.ts /home/loic/blitz-orm/src/stateMachine/query/surql/machine.ts /home/loic/blitz-orm/src/stateMachine/query/tql/machine.ts

FIles to change: /home/loic/blitz-orm/tests/unit/queries/query.ts

Instructions:

  • Dont delete existing tests
  • Keep the same structure as existing tests, which use ctx.query( ..)
  • Ensure you re not creating duplicate tests
  • Prefix the tests depending on their category, similar to what happens on the existing tests
  • Use the preset of data (the one defined in both formats here /home/loic/blitz-orm/tests/surrealdb/mocks/data.surql and here /home/loic/blitz-orm/tests/typedb/mocks/data.tql //This is the same data set equivalent, for typeDB
  • Take a deep breath and structure your work to fill only the missing tests and current blind spots

lveillard avatar Jun 02 '24 21:06 lveillard

Sweeping

75%

Actions

  • [ ] ↻ Restart Sweep

❌ Unable to Complete PR

I'm sorry, but it looks like an error has occurred due to a code validation failure. The error message is . Here were the changes I had planned:

/home/loic/blitz-orm/tests/unit/queries/query.ts

--- 
+++ 
@@ -1 +1,185 @@
-// Existing test cases
+// Existing test cases
+
+// New test cases
+
+it('should query entities with nested link fields targeting relations', async () => {
+  const res = await ctx.query([
+    {
+      $thing: 'User',
+      $fields: [
+        'id',
+        'name',
+        {
+          $path: 'spaces',
+          $fields: ['id', 'name']
+        }
+      ]
+    }
+  ]);
+
+  expect(res).toEqual([
+    {
+      id: 'user-1',
+      name: 'John',
+      spaces: [
+        {
+          id: 'space-1',
+          name: 'Space 1'
+        },
+        {
+          id: 'space-2',
+          name: 'Space 2'
+        }
+      ]
+    },
+    {
+      id: 'user-2',
+      name: 'Jane',
+      spaces: [
+        {
+          id: 'space-3',
+          name: 'Space 3'
+        }
+      ]
+    }
+  ]);
+});
+
+it('should query entities with nested link fields targeting roles', async () => {
+  const res = await ctx.query([
+    {
+      $thing: 'Space',
+      $fields: [
+        'id',
+        'name',
+        {
+          $path: 'users',
+          $fields: ['id', 'name']
+        }
+      ]
+    }
+  ]);
+
+  expect(res).toEqual([
+    {
+      id: 'space-1',
+      name: 'Space 1',
+      users: [
+        {
+          id: 'user-1',
+          name: 'John'
+        }
+      ]
+    },
+    {
+      id: 'space-2',
+      name: 'Space 2',
+      users: [
+        {
+          id: 'user-1',
+          name: 'John'
+        }
+      ]
+    },
+    {
+      id: 'space-3',
+      name: 'Space 3',
+      users: [
+        {
+          id: 'user-2',
+          name: 'Jane'
+        }
+      ]
+    }
+  ]);
+});
+
+it('should query relations with nested role fields', async () => {
+  const res = await ctx.query([
+    {
+      $thing: 'Space-User',
+      $fields: [
+        {
+          $path: 'users',
+          $fields: ['id', 'name']
+        },
+        {
+          $path: 'spaces',
+          $fields: ['id', 'name']
+        }
+      ]
+    }
+  ]);
+
+  expect(res).toEqual([
+    {
+      users: {
+        id: 'user-1',
+        name: 'John'
+      },
+      spaces: {
+        id: 'space-1',
+        name: 'Space 1'
+      }
+    },
+    {
+      users: {
+        id: 'user-1',
+        name: 'John'
+      },
+      spaces: {
+        id: 'space-2',
+        name: 'Space 2'
+      }
+    },
+    {
+      users: {
+        id: 'user-2',
+        name: 'Jane'
+      },
+      spaces: {
+        id: 'space-3',
+        name: 'Space 3'
+      }
+    }
+  ]);
+});
+
+it('should combine filters, sorting, and pagination with different field types', async () => {
+  const res = await ctx.query([
+    {
+      $thing: 'User',
+      $fields: [
+        'id',
+        'name',
+        {
+          $path: 'spaces',
+          $fields: ['id', 'name'],
+          $filter: {
+            name: 'Space 1'
+          },
+          $sort: ['name'],
+          $limit: 1
+        }
+      ],
+      $filter: {
+        name: 'John'
+      },
+      $sort: ['name'],
+      $limit: 1
+    }
+  ]);
+
+  expect(res).toEqual([
+    {
+      id: 'user-1',
+      name: 'John',
+      spaces: [
+        {
+          id: 'space-1',
+          name: 'Space 1'
+        }
+      ]
+    }
+  ]);
+});

Feel free to add more details to the issue description so Sweep can better address it. Alternatively, reach out to Kevin or William for help at https://community.sweep.dev/.

Report a bug.


[!TIP] To recreate the pull request, edit the issue title or description.

This is an automated message generated by Sweep AI.