|
1 | | -describe("the resource property", function () { |
| 1 | +describe("the resources property", function () { |
2 | 2 |
|
3 | 3 | beforeEach(beforeEachFunction); |
4 | 4 |
|
5 | | - it("must return the resources of the object", function () { |
6 | | - this.rawResponse = mockData(); |
7 | | - this.response = new SpringDataRestAdapter(this.rawResponse); |
| 5 | + it("must contain the 'links key' key", function () { |
| 6 | + expect(this.response[this.config.links.key]).toBeDefined(); |
| 7 | + }); |
| 8 | + |
| 9 | + it("must call the correct href url if a resource name is passed to the $resource method", function () { |
| 10 | + |
| 11 | + // define the resource name and the correct resource href url |
| 12 | + var resourceName = "self"; |
| 13 | + var resourceHref = "http://localhost:8080/categories"; |
| 14 | + |
| 15 | + // check if the underlying $resource method is called with the correct href url |
| 16 | + var expectedResult = {categoryId: '123'}; |
| 17 | + this.httpBackend.whenGET(resourceHref).respond(200, expectedResult); |
| 18 | + this.httpBackend.expectGET(resourceHref); |
| 19 | + var result = this.response[this.config.resourcesKey](resourceName).get(function () { |
| 20 | + expect(result.categoryId).toEqual(expectedResult.categoryId); |
| 21 | + }); |
| 22 | + this.httpBackend.flush(); |
| 23 | + }); |
| 24 | + |
| 25 | + it("must call the correct href url if a resource object is passed to the $resource method", function () { |
| 26 | + |
| 27 | + // define the resource object and the correct link href url |
| 28 | + var resourceObject = { |
| 29 | + 'name': 'self' |
| 30 | + }; |
| 31 | + var resourceHref = "http://localhost:8080/categories"; |
| 32 | + |
| 33 | + // check if the underlying $resource method is called with the correct href url |
| 34 | + var expectedResult = {categoryId: '123'}; |
| 35 | + this.httpBackend.whenGET(resourceHref).respond(200, expectedResult); |
| 36 | + this.httpBackend.expectGET(resourceHref); |
| 37 | + var result = this.response[this.config.resourcesKey](resourceObject).get(function () { |
| 38 | + expect(result.categoryId).toEqual(expectedResult.categoryId); |
| 39 | + }); |
| 40 | + this.httpBackend.flush(); |
| 41 | + }); |
| 42 | + |
| 43 | + it("must throw an exception if a wrong resource object is given", function () { |
| 44 | + // expect that the resources method is present |
| 45 | + expect(this.response[this.config.resourcesKey]).toBeDefined(); |
| 46 | + |
| 47 | + var thisResponse = this.response; |
| 48 | + var thisResourceKey = this.config.resourcesKey; |
| 49 | + var thisHttpBackend = this.httpBackend; |
| 50 | + |
| 51 | + // it must throw an exception if a wrong resource object is given |
| 52 | + expect(function () { |
| 53 | + expectResourceExecution(thisResponse, thisResourceKey, |
| 54 | + "expectedUrl", thisHttpBackend, {'wrongPropertyName': 'value'}); |
| 55 | + }).toThrow("The provided resource object must contain a name property."); |
| 56 | + }); |
| 57 | + |
| 58 | + it("must not use any parameters if the resource object is a string and no parameters are given", function () { |
| 59 | + // expect that the resources method is present |
| 60 | + expect(this.response[this.config.resourcesKey]).toBeDefined(); |
| 61 | + |
| 62 | + // the parameters must not be used in the resources method |
| 63 | + expectResourceExecution(this.response, this.config.resourcesKey, |
| 64 | + this.response[this.config.links.key]["self"].href, this.httpBackend, "self") |
| 65 | + }); |
| 66 | + |
| 67 | + it("must use the given parameters if the resource object is a string", function () { |
| 68 | + // expect that the resources method is present |
| 69 | + expect(this.response[this.config.resourcesKey]).toBeDefined(); |
| 70 | + |
| 71 | + // the given parameters must be used in the resources method |
| 72 | + expectResourceExecution(this.response, this.config.resourcesKey, |
| 73 | + this.response[this.config.links.key]["self"].href + "?parameterName=parameterValue", this.httpBackend, "self", |
| 74 | + {'parameterName': 'parameterValue'}); |
| 75 | + }); |
| 76 | + |
| 77 | + it("must use the resource name if the correct resource object is given", function () { |
| 78 | + // expect that the resources method is present |
| 79 | + expect(this.response[this.config.resourcesKey]).toBeDefined(); |
| 80 | + |
| 81 | + // the given resource name must be used |
| 82 | + expectResourceExecution(this.response, this.config.resourcesKey, |
| 83 | + this.response[this.config.links.key]["self"].href, this.httpBackend, {'name': 'self'}) |
| 84 | + }); |
| 85 | + |
| 86 | + it("must use the correct resource object name and the given parameters", function () { |
| 87 | + // expect that the resources method is present |
| 88 | + expect(this.response[this.config.resourcesKey]).toBeDefined(); |
| 89 | + |
| 90 | + // the given parameters must be used in the resources method |
| 91 | + expectResourceExecution(this.response, this.config.resourcesKey, |
| 92 | + this.response[this.config.links.key]["self"].href + "?parameterName=parameterValue", |
| 93 | + this.httpBackend, {'name': 'self'}, {'parameterName': 'parameterValue'}) |
| 94 | + }); |
| 95 | + |
| 96 | + it("must use the correct resource object name and parameters", function () { |
| 97 | + // expect that the resources method is present |
| 98 | + expect(this.response[this.config.resourcesKey]).toBeDefined(); |
| 99 | + |
| 100 | + // the given parameters must be used in the resources method |
| 101 | + expectResourceExecution(this.response, this.config.resourcesKey, |
| 102 | + this.response[this.config.links.key]["self"].href + "?parameterName=parameterValue", |
| 103 | + this.httpBackend, {'name': 'self', 'parameters': {'parameterName': 'parameterValue'}}) |
| 104 | + }); |
8 | 105 |
|
| 106 | + it("must use the correct resource object name and merge the resource object parameters with the given parameters", function () { |
| 107 | + // expect that the resources method is present |
| 108 | + expect(this.response[this.config.resourcesKey]).toBeDefined(); |
| 109 | + |
| 110 | + // the given parameters must be used in the resources method |
| 111 | + expectResourceExecution(this.response, this.config.resourcesKey, |
| 112 | + this.response[this.config.links.key]["self"].href + "?objectParameterName=objectParameterValue¶meterName=parameterValue", |
| 113 | + this.httpBackend, {'name': 'self', 'parameters': {'objectParameterName': 'objectParameterValue'}}, |
| 114 | + {'parameterName': 'parameterValue'}) |
| 115 | + }); |
| 116 | + |
| 117 | + it("must return the resources of the object", function () { |
9 | 118 | // expect that the resources method is present |
10 | 119 | expect(this.response[this.config.resourcesKey]).toBeDefined(); |
11 | 120 |
|
|
0 commit comments