This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
forked from jaystack/odata-v4-server
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
270 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { shutdown } from '../utils/server'; | ||
import { Class, RelStudentClassAssignment, SchoolEntities, Student, Teacher } from './school_model'; | ||
import { createServerAndClient } from './utils'; | ||
|
||
describe('Typed OData Server Integration Test Suite', () => { | ||
|
||
it('should run total integration tests', async () => { | ||
|
||
const { server, client } = await createServerAndClient({ | ||
name: 'typed_server_integration_test_conn', | ||
type: 'sqljs', synchronize: true, | ||
entities: SchoolEntities | ||
}, ...SchoolEntities); | ||
|
||
try { | ||
const students = client.getEntitySet<Student>('Students'); | ||
const classes = client.getEntitySet<Class>('Classes'); // renamed by decorator | ||
const teachers = client.getEntitySet<Teacher>('Teachers'); | ||
const classRegistry = client.getEntitySet<RelStudentClassAssignment>('RelStudentClassAssignments'); | ||
|
||
const t1 = await teachers.create({ name: 'turing' }); | ||
const s1 = await students.create({ name: 'theo' }); | ||
const c1 = await classes.create({ | ||
name: 'computer science', | ||
teacherOneId: t1.id, | ||
desc: 'Computer science is the study of computation and information.' | ||
}); | ||
const r1 = await classRegistry.create({ classId: c1.id, studentId: s1.id }); | ||
|
||
const full = await classes.retrieve(c1.id, client.newParam().expand('students($expand=student)')); | ||
|
||
expect(full).toMatchObject({ | ||
'id': c1.id, | ||
'name': c1.name, | ||
'desc': c1.desc, | ||
'teacherOneId': t1.id, | ||
'students': [ | ||
{ | ||
'uuid': r1.uuid, | ||
'studentId': s1.id, | ||
'classId': c1.id, | ||
'student': { | ||
'id': s1.id, | ||
'name': 'theo', | ||
'age': null | ||
} | ||
} | ||
] | ||
}); | ||
|
||
} finally { | ||
await shutdown(server); | ||
} | ||
|
||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { BaseODataModel, ODataColumn, ODataEntitySetName, ODataModel, ODataNavigation } from '../../../lib'; | ||
import { RelStudentClassAssignment } from './Rel'; | ||
import { Teacher } from './Teacher'; | ||
|
||
// indicate the entity set name for entity | ||
@ODataEntitySetName('Classes') | ||
@ODataModel() | ||
export class Class extends BaseODataModel { | ||
|
||
@ODataColumn({ primary: true, generated: 'increment' }) | ||
id: number; | ||
|
||
@ODataColumn() | ||
name: string; | ||
|
||
@ODataColumn() | ||
desc: string | ||
|
||
@ODataColumn({ nullable: true }) | ||
teacherOneId: number; | ||
|
||
@ODataNavigation({ type: 'ManyToOne', entity: () => Teacher, foreignKey: 'teacherOneId' }) | ||
teacher: any; | ||
|
||
// GET http://localhost:50000/Classes?$expand=students($expand=student) | ||
@ODataNavigation({ type: 'OneToMany', entity: () => RelStudentClassAssignment, foreignKey: 'classId' }) | ||
students: any; | ||
|
||
} |
Oops, something went wrong.