|
|
|
@ -35,72 +35,105 @@ const expect = chai.expect; |
|
|
|
|
describe('halResourceTypes service', () => { |
|
|
|
|
var halResourceTypes:HalResourceTypesService; |
|
|
|
|
var halResourceTypesStorage:HalResourceTypesStorageService; |
|
|
|
|
var config:any; |
|
|
|
|
var compareCls:typeof HalResource; |
|
|
|
|
|
|
|
|
|
class HalResource { |
|
|
|
|
} |
|
|
|
|
class OtherResource { |
|
|
|
|
} |
|
|
|
|
class FooResource { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
beforeEach(angular.mock.module(opApiModule.name, $provide => { |
|
|
|
|
$provide.value('HalResource', HalResource); |
|
|
|
|
$provide.value('OtherResource', OtherResource); |
|
|
|
|
$provide.value('FooResource', FooResource); |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject((_halResourceTypes_, _halResourceTypesStorage_) => { |
|
|
|
|
[halResourceTypes, halResourceTypesStorage] = arguments; |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
it('should exist', () => { |
|
|
|
|
expect(halResourceTypes).to.exist; |
|
|
|
|
const expectResourceClassAdded = () => { |
|
|
|
|
it('should add the respective class object to the storage', () => { |
|
|
|
|
const cls = halResourceTypesStorage.getResourceClassOfType('Other'); |
|
|
|
|
expect(cls).to.equal(compareCls); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('when adding configuration', () => { |
|
|
|
|
var chained; |
|
|
|
|
var commonTests = () => { |
|
|
|
|
it('should return itself', () => { |
|
|
|
|
expect(chained).to.equal(halResourceTypes); |
|
|
|
|
const expectAttributeClassAdded = () => { |
|
|
|
|
it('should add the attribute type config to the storage', () => { |
|
|
|
|
const cls = halResourceTypesStorage.getResourceClassOfAttribute('Other', 'attr'); |
|
|
|
|
expect(cls).to.equal(compareCls); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
it('should add the attribute type config', () => { |
|
|
|
|
const resource = halResourceTypesStorage |
|
|
|
|
.getResourceClassOfAttribute('Other', 'someResource'); |
|
|
|
|
it('should exist', () => { |
|
|
|
|
expect(halResourceTypes).to.exist; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
expect(resource).to.equal(OtherResource); |
|
|
|
|
it('should have added HalResource as the default type', () => { |
|
|
|
|
expect(halResourceTypesStorage.defaultClass).to.equal(HalResource); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
describe('when no class name is provided and attributes are configured', () => { |
|
|
|
|
describe('when configuring the type with class and attributes', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
chained = halResourceTypes.addType('Other', { |
|
|
|
|
attr: { |
|
|
|
|
someResource: 'OtherResource' |
|
|
|
|
compareCls = OtherResource; |
|
|
|
|
config = { |
|
|
|
|
Other: { |
|
|
|
|
className: 'OtherResource', |
|
|
|
|
attrTypes: { |
|
|
|
|
attr: 'Other' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
halResourceTypes.setResourceTypeConfig(config); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
expectResourceClassAdded(); |
|
|
|
|
expectAttributeClassAdded(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should add the respective class object', () => { |
|
|
|
|
expect(halResourceTypesStorage.getResourceClassOfType('Other')).to.equal(HalResource); |
|
|
|
|
describe('when configuring the type with the class name as value', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
compareCls = OtherResource; |
|
|
|
|
config = { |
|
|
|
|
Other: 'OtherResource' |
|
|
|
|
}; |
|
|
|
|
halResourceTypes.setResourceTypeConfig(config); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
commonTests(); |
|
|
|
|
expectResourceClassAdded(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('when a class name is provided and attribute types are configured', () => { |
|
|
|
|
describe('when configuring the type with only the attribute types', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
chained = halResourceTypes.addType('Other', { |
|
|
|
|
className: 'OtherResource', |
|
|
|
|
attr: { |
|
|
|
|
someResource: 'OtherResource' |
|
|
|
|
compareCls = halResourceTypesStorage.defaultClass; |
|
|
|
|
config = { |
|
|
|
|
Other: { |
|
|
|
|
attr: 'Other' |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
halResourceTypes.setResourceTypeConfig(config); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should have the default type', () => { |
|
|
|
|
expect(halResourceTypesStorage.getResourceClassOfType('Other')).to.equal(OtherResource); |
|
|
|
|
expectResourceClassAdded(); |
|
|
|
|
expectAttributeClassAdded(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
commonTests(); |
|
|
|
|
describe('when an attribute has a type, that defined later in the config', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
compareCls = FooResource; |
|
|
|
|
config = { |
|
|
|
|
Other: { |
|
|
|
|
attr: 'Foo' |
|
|
|
|
}, |
|
|
|
|
Foo: 'FooResource', |
|
|
|
|
}; |
|
|
|
|
halResourceTypes.setResourceTypeConfig(config); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
expectAttributeClassAdded(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|