1 import {IdlService} from './idl.service';
3 describe('IdlService', () => {
4 let service: IdlService;
6 service = new IdlService();
9 it('should parse the IDL', () => {
11 expect(service.classes['aou'].fields.length).toBeGreaterThan(0);
14 it('should create an aou object', () => {
16 const org = service.create('aou');
17 expect(typeof org.id).toBe('function');
20 it('should create an aou object with accessor/mutators', () => {
22 const org = service.create('aou');
24 expect(org.name()).toBe('AN ORG');
27 it('should correctly compare IDL pkey values', () => {
29 const org1 = service.create('aou');
30 const org2 = service.create('aou');
33 expect(service.pkeyMatches(org1, org2)).toBe(true);
36 it('should correctly compare IDL pkey values', () => {
38 const org1 = service.create('aou');
39 const org2 = service.create('aou');
42 expect(service.pkeyMatches(org1, org2)).toBe(false);
45 it('should correctly compare IDL classes in pkey match', () => {
47 const org = service.create('aou');
48 const user = service.create('au');
51 expect(service.pkeyMatches(org, user)).toBe(false);
54 it('should sort an array of IDL fields according to an array of field names', () => {
55 const fieldNames = ['name', 'owner', 'active', 'id'];
57 {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
58 {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
59 {'name': 'active', 'datatype': 'bool'},
60 {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'}
62 const expectedOrder = [
63 {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
64 {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'},
65 {'name': 'active', 'datatype': 'bool'},
66 {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
68 expect(service.sortIdlFields(idlFields, fieldNames)).toEqual(expectedOrder);
71 it('should sort IDL fields by label when it runs out of specified field names', () => {
72 const fieldNames = ['owner'];
74 {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
75 {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
76 {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'}
78 const expectedOrder = [
79 {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'},
80 {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
81 {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
83 expect(service.sortIdlFields(idlFields, fieldNames)).toEqual(expectedOrder);
86 it('should sort IDL fields by name when it runs out of other ways to sort', () => {
87 const fieldNames = ['owner'];
89 {'name': 'id', 'dataType': 'id'},
90 {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
91 {'name': 'active', 'datatype': 'bool'},
92 {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'}
94 const expectedOrder = [
95 {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'},
96 {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
97 {'name': 'active', 'datatype': 'bool'},
98 {'name': 'id', 'dataType': 'id'},
100 expect(service.sortIdlFields(idlFields, fieldNames)).toEqual(expectedOrder);