Skip to content

Commit

Permalink
test(cli): adding more test for prisma format (#6234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamshankhadeep committed Mar 25, 2021
1 parent 14ffd00 commit 4e5f93f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/packages/cli/src/__tests__/__snapshots__/format.test.ts.snap
Expand Up @@ -37,3 +37,27 @@ model User {
}
`;
exports[`format should add missing backrelation 1`] = `
generator client {
provider = "prisma-client-js"
output = "***"
}
datasource db {
provider = "sqlite"
url = "***"
}
model Post {
id Int @id
user User @relation(fields: [userId], references: [id])
userId Int
}
model User {
id Int @id
posts Post[]
}
`;
@@ -0,0 +1 @@
it has broken schema
@@ -0,0 +1,19 @@
generator client {
provider = "prisma-client-js"
output = "../generated/client"
}

datasource db {
provider = "sqlite"
url = "file:dev.db"
}

model Post {
id Int @id
user User
}

model User {
id Int @id
posts Post[]
}
13 changes: 13 additions & 0 deletions src/packages/cli/src/__tests__/format.test.ts
Expand Up @@ -9,3 +9,16 @@ it('format should add a trailing EOL', async () => {
await Format.new().parse([])
expect(fs.read('schema.prisma')).toMatchSnapshot()
})

it('format should add missing backrelation', async () => {
ctx.fixture('example-project/prisma')
await Format.new().parse(['--schema=missing-backrelation.prisma'])
expect(fs.read('missing-backrelation.prisma')).toMatchSnapshot()
})

it('format should throw if schema is broken', async () => {
ctx.fixture('example-project/prisma')
await expect(
Format.new().parse(['--schema=broken.prisma']),
).rejects.toThrowError()
})

0 comments on commit 4e5f93f

Please sign in to comment.