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(casing): add case sensitivity tests #1386

Merged
merged 1 commit into from
Oct 18, 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
1 change: 1 addition & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: integration test all
on: pull_request
jobs:
integration:
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
Expand Down
75 changes: 75 additions & 0 deletions test/features/casing/default_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package db

import (
"context"
"testing"

"github.com/steebchen/prisma-client-go/test"
"github.com/steebchen/prisma-client-go/test/helpers/massert"
)

type cx = context.Context
type Func func(t *testing.T, client *PrismaClient, ctx cx)

func TestCaseSensitivity(t *testing.T) {
tests := []struct {
name string
before []string
run Func
}{{
name: "case sensitivity",
before: nil,
run: func(t *testing.T, client *PrismaClient, ctx cx) {
user, err := client.User.CreateOne(
User.Name.Set("THIS is me"),
User.ID.Set("123"),
).Exec(ctx)
if err != nil {
t.Fatal(err)
}

expected := &UserModel{
InnerUser: InnerUser{
ID: "123",
Name: "THIS is me",
},
}

massert.Equal(t, expected, user)

user, err = client.User.FindFirst(
User.And(
User.Name.Contains("THIS"),
User.Name.Mode(QueryModeInsensitive),
),
).Exec(ctx)
if err != nil {
t.Fatal(err)
}

massert.Equal(t, expected, user)

user, err = client.User.FindFirst(
User.Name.Contains("this"),
User.Name.Mode(QueryModeInsensitive),
).Exec(ctx)
if err != nil {
t.Fatal(err)
}

massert.Equal(t, expected, user)
},
}}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
test.RunSerial(t, []test.Database{test.MongoDB, test.PostgreSQL}, func(t *testing.T, db test.Database, ctx context.Context) {
client := NewClient()
mockDBName := test.Start(t, db, client.Engine, tt.before)
defer test.End(t, db, client.Engine, mockDBName)
tt.run(t, client, context.Background())
})
})
}
}
16 changes: 16 additions & 0 deletions test/features/casing/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
datasource db {
provider = "postgresql"
url = env("__REPLACE__")
}

generator db {
provider = "go run github.com/steebchen/prisma-client-go"
output = "."
disableGoBinaries = true
package = "db"
}

model User {
id String @id @default(cuid()) @map("_id")
name String
}
Loading