I have the following schema
model Tenant {
id Int @id @default(autoincrement())
name String
users User[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model User {
id Int @id @default(autoincrement())
tenants Tenant[]
email String @unique
hashedPassword String
salt String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Where a user can have 1 or more tenants and a tenant can have 1 or more users. This is working fine so far, up until my test started failing. I updated my user and tenant querys to start returning the relations like so:
export const user = async ({ id }) => {
const oneUser = await db.user.findUnique({
where: { id },
});
const tenants = await db.user
.findUnique({
where: { id },
})
.tenants();
return {
...oneUser,
tenants,
};
};
I have a scenerio setup like this
user: {
one: {
data: {
email: 'test-user-1@example.com',
hashedPassword: 'my-super-top-secret-passw0rd',
salt: '02EDGWDWOKJH842NZZ',
updatedAt: new Date('2022-06-18T19:08:06Z'),
tenants: {
create: [
{
name: 'test-tenant-1',
updatedAt: new Date('2022-06-18T19:08:06Z'),
},
],
},
},
},
},
Here is my test
scenario('returns a single user', async (scenario) => {
const result = await user({ id: scenario.user.one.id });
expect(result).toEqual(scenario.user.one);
});
result
contains a tenant
but scenario
does not. Any idea why or how to work-around this? I get this error
● users › returns a single user
expect(received).toEqual(expected) // deep equality
- Expected - 0
+ Received + 1
@@ -5,8 +5,9 @@
"id": 14,
"salt": "02EDGWDWOKJH842NZZ",
+ "tenants": Array [],
"updatedAt": 2022-06-18T19:08:06.000Z,
"verification": "test-verification-c0de",
}
25 | const result = await user({ id: scenario.user.one.id });
26 |
> 27 | expect(result).toEqual(scenario.user.one);
| ^
28 | });
29 |
30 | scenario('creates a user', async () => {
at api/src/services/users/users.test.js:27:20
at Object.<anonymous> (node_modules/@redwoodjs/testing/config/jest/api/jest.setup.js:163:16)