|
| 1 | +import { createTestClient } from '@zenstackhq/testtools'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +describe('Regression for issue 651', () => { |
| 5 | + it('float array queries should work with all operators on PostgreSQL', async () => { |
| 6 | + const db = await createTestClient( |
| 7 | + ` |
| 8 | +model User { |
| 9 | + id Int @id @default(autoincrement()) |
| 10 | + email String @unique |
| 11 | + floatArray Float[] |
| 12 | +} |
| 13 | + `, |
| 14 | + { provider: 'postgresql', usePrismaPush: true }, |
| 15 | + ); |
| 16 | + |
| 17 | + // Create test users with different float arrays |
| 18 | + const user1 = await db.user.create({ |
| 19 | + data: { |
| 20 | + email: 'user1@example.com', |
| 21 | + floatArray: [1.1, 2.2, 3.3], |
| 22 | + }, |
| 23 | + }); |
| 24 | + |
| 25 | + const user2 = await db.user.create({ |
| 26 | + data: { |
| 27 | + email: 'user2@example.com', |
| 28 | + floatArray: [1.1, 2.2, 3.3, 4.4, 5.5], |
| 29 | + }, |
| 30 | + }); |
| 31 | + |
| 32 | + const user3 = await db.user.create({ |
| 33 | + data: { |
| 34 | + email: 'user3@example.com', |
| 35 | + floatArray: [], |
| 36 | + }, |
| 37 | + }); |
| 38 | + |
| 39 | + // Test 'equals' operator |
| 40 | + const equalsResult = await db.user.findMany({ |
| 41 | + where: { |
| 42 | + floatArray: { |
| 43 | + equals: [1.1, 2.2, 3.3], |
| 44 | + }, |
| 45 | + }, |
| 46 | + }); |
| 47 | + expect(equalsResult).toHaveLength(1); |
| 48 | + expect(equalsResult[0].id).toBe(user1.id); |
| 49 | + |
| 50 | + // Test 'has' operator - contains single value |
| 51 | + const hasResult = await db.user.findMany({ |
| 52 | + where: { |
| 53 | + floatArray: { |
| 54 | + has: 4.4, |
| 55 | + }, |
| 56 | + }, |
| 57 | + }); |
| 58 | + expect(hasResult).toHaveLength(1); |
| 59 | + expect(hasResult[0].id).toBe(user2.id); |
| 60 | + |
| 61 | + // Test 'hasSome' operator - contains any of the values |
| 62 | + const hasSomeResult = await db.user.findMany({ |
| 63 | + where: { |
| 64 | + floatArray: { |
| 65 | + hasSome: [3.3, 6.6, 7.7], |
| 66 | + }, |
| 67 | + }, |
| 68 | + }); |
| 69 | + expect(hasSomeResult).toHaveLength(2); |
| 70 | + expect(hasSomeResult.map((u: any) => u.id).sort()).toEqual([user1.id, user2.id].sort()); |
| 71 | + |
| 72 | + // Test 'hasEvery' operator - contains all values |
| 73 | + const hasEveryResult = await db.user.findMany({ |
| 74 | + where: { |
| 75 | + floatArray: { |
| 76 | + hasEvery: [1.1, 2.2], |
| 77 | + }, |
| 78 | + }, |
| 79 | + }); |
| 80 | + expect(hasEveryResult).toHaveLength(2); |
| 81 | + expect(hasEveryResult.map((u: any) => u.id).sort()).toEqual([user1.id, user2.id].sort()); |
| 82 | + |
| 83 | + // Test 'isEmpty' operator |
| 84 | + const isEmptyResult = await db.user.findMany({ |
| 85 | + where: { |
| 86 | + floatArray: { |
| 87 | + isEmpty: true, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }); |
| 91 | + expect(isEmptyResult).toHaveLength(1); |
| 92 | + expect(isEmptyResult[0].id).toBe(user3.id); |
| 93 | + |
| 94 | + // Test 'isEmpty: false' |
| 95 | + const notEmptyResult = await db.user.findMany({ |
| 96 | + where: { |
| 97 | + floatArray: { |
| 98 | + isEmpty: false, |
| 99 | + }, |
| 100 | + }, |
| 101 | + }); |
| 102 | + expect(notEmptyResult).toHaveLength(2); |
| 103 | + expect(notEmptyResult.map((u: any) => u.id).sort()).toEqual([user1.id, user2.id].sort()); |
| 104 | + }); |
| 105 | +}); |
0 commit comments