Skip to content

Commit efae431

Browse files
chore: wip
1 parent 473033b commit efae431

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

storage/framework/orm/src/tests/Models.test.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,4 +978,146 @@ describe('Models test', () => {
978978
expect(results.length).toBe(1)
979979
expect(results[0]?.name).toBe('Jane')
980980
})
981+
982+
it('should handle whereRef for column comparisons', async () => {
983+
await User.create({
984+
name: 'John Smith',
985+
job_title: 'John Smith', // Same as name
986+
email: 'john@test.com',
987+
password: '123456',
988+
})
989+
await User.create({
990+
name: 'Jane Doe',
991+
job_title: 'Developer', // Different from name
992+
email: 'jane@test.com',
993+
password: '123456',
994+
})
995+
996+
const results = await User.whereRef('name', '=', 'job_title').get()
997+
expect(results.length).toBe(1)
998+
expect(results[0]?.name).toBe('John Smith')
999+
})
1000+
1001+
it('should handle whereRaw queries', async () => {
1002+
await User.create({
1003+
name: 'John',
1004+
job_title: 'Developer',
1005+
email: 'john@test.com',
1006+
password: '123456',
1007+
})
1008+
1009+
const results = await User.whereRaw('UPPER(name) = \'JOHN\'').get()
1010+
expect(results.length).toBe(1)
1011+
expect(results[0]?.name).toBe('John')
1012+
})
1013+
1014+
// it('should load multiple relations using with()', async () => {
1015+
// const user = await User.create({
1016+
// name: 'John',
1017+
// job_title: 'Developer',
1018+
// email: 'john@test.com',
1019+
// password: '123456',
1020+
// })
1021+
1022+
// // Create some related records
1023+
// await DB.instance.insertInto('posts').values([
1024+
// { user_id: user.id, title: 'Post 1' }
1025+
// ]).execute()
1026+
1027+
// await DB.instance.insertInto('subscriptions').values([
1028+
// { user_id: user.id, plan: 'basic' }
1029+
// ]).execute()
1030+
1031+
// const result = await User.with(['posts', 'subscriptions']).find(user.id!)
1032+
// expect(result?.posts).toBeDefined()
1033+
// expect(result?.subscriptions).toBeDefined()
1034+
// })
1035+
1036+
it('should handle whereRef for column comparisons', async () => {
1037+
await User.create({
1038+
name: 'John Smith',
1039+
job_title: 'John Smith', // Same as name
1040+
email: 'john@test.com',
1041+
password: '123456',
1042+
})
1043+
await User.create({
1044+
name: 'Jane Doe',
1045+
job_title: 'Developer', // Different from name
1046+
email: 'jane@test.com',
1047+
password: '123456',
1048+
})
1049+
1050+
const results = await User.whereRef('name', '=', 'job_title').get()
1051+
expect(results.length).toBe(1)
1052+
expect(results[0]?.name).toBe('John Smith')
1053+
})
1054+
1055+
it('should handle whereRaw queries', async () => {
1056+
await User.create({
1057+
name: 'John',
1058+
job_title: 'Developer',
1059+
email: 'john@test.com',
1060+
password: '123456',
1061+
})
1062+
1063+
const results = await User.whereRaw('UPPER(name) = \'JOHN\'').get()
1064+
expect(results.length).toBe(1)
1065+
expect(results[0]?.name).toBe('John')
1066+
})
1067+
1068+
// it('should load multiple relations using with()', async () => {
1069+
// const user = await User.create({
1070+
// name: 'John',
1071+
// job_title: 'Developer',
1072+
// email: 'john@test.com',
1073+
// password: '123456',
1074+
// })
1075+
1076+
// // Create some related records
1077+
// await DB.instance.insertInto('posts').values([
1078+
// { user_id: user.id, title: 'Post 1' }
1079+
// ]).execute()
1080+
1081+
// await DB.instance.insertInto('subscriptions').values([
1082+
// { user_id: user.id, plan: 'basic' }
1083+
// ]).execute()
1084+
1085+
// const result = await User.with(['posts', 'subscriptions']).find(user.id!)
1086+
// expect(result?.posts).toBeDefined()
1087+
// expect(result?.subscriptions).toBeDefined()
1088+
// })
1089+
1090+
it('should combine where and whereNull conditions', async () => {
1091+
await User.create({
1092+
name: 'John',
1093+
job_title: 'Developer',
1094+
email: 'john@test.com',
1095+
password: '123456',
1096+
updated_at: new Date()
1097+
})
1098+
await User.create({
1099+
name: 'Jane',
1100+
job_title: 'Designer',
1101+
email: 'jane@test.com',
1102+
password: '123456',
1103+
})
1104+
1105+
const results = await User.where('name', 'like', 'J%').whereNull('updated_at').get()
1106+
expect(results.length).toBe(1)
1107+
expect(results[0]?.name).toBe('Jane')
1108+
})
1109+
1110+
it('should handle select with specific columns', async () => {
1111+
await User.create({
1112+
name: 'John',
1113+
job_title: 'Developer',
1114+
email: 'john@test.com',
1115+
password: '123456',
1116+
})
1117+
1118+
const results = await User.select(['name', 'email']).first()
1119+
expect(results?.name).toBeDefined()
1120+
expect(results?.email).toBeDefined()
1121+
expect(results?.job_title).toBeUndefined()
1122+
})
9811123
})

0 commit comments

Comments
 (0)