()
| 18 | } |
| 19 | |
| 20 | protected tests() { |
| 21 | test("valueHasExpired should return true if the timestamped data is older than the expiry time", () => { |
| 22 | let expiry = 500; |
| 23 | let value = { |
| 24 | data: {}, |
| 25 | lastUpdated: Date.now() - (expiry + 1) |
| 26 | }; |
| 27 | |
| 28 | ok(CachedHttp.valueHasExpired(value, expiry), |
| 29 | "A timestamped value with a lastUpdated value older than the expiry should return true"); |
| 30 | }); |
| 31 | |
| 32 | test("valueHasExpired should return false if the timestamped data is not older than the expiry time", () => { |
| 33 | let expiry = 999999999999; |
| 34 | let value = { |
| 35 | data: {}, |
| 36 | lastUpdated: Date.now() |
| 37 | }; |
| 38 | |
| 39 | ok(!CachedHttp.valueHasExpired(value, expiry), |
| 40 | "A timestamped value with a lastUpdated value newer than the expiry should return false"); |
| 41 | }); |
| 42 | |
| 43 | test("valueHasExpired should return true if value is undefined", () => { |
| 44 | let expiry = 999999999999; |
| 45 | ok(CachedHttp.valueHasExpired(undefined, expiry), |
| 46 | "A timestamped value with an undefined value should return true"); |
| 47 | }); |
| 48 | |
| 49 | test("valueHasExpired should return true if value is undefined", () => { |
| 50 | let expiry = 999999999999; |
| 51 | let value = { |
| 52 | data: {}, |
| 53 | lastUpdated: undefined |
| 54 | }; |
| 55 | |
| 56 | ok(CachedHttp.valueHasExpired(value, expiry), |
| 57 | "A timestamped value with an undefined value should return true"); |
| 58 | }); |
| 59 | |
| 60 | test("getFreshValue where the value in storage is still fresh should not return or retrieve the value from the specified remote call", (assert: QUnitAssert) => { |
| 61 | let done = assert.async(); |
| 62 | |
| 63 | let expected = "expected"; |
| 64 | let timeOfStorage = Date.now(); |
| 65 | let valueInStorage = { |
| 66 | data: expected, |
| 67 | lastUpdated: timeOfStorage |
| 68 | }; |
| 69 | |
| 70 | let key = "k"; |
| 71 | this.mockStorage.setValue(key, JSON.stringify(valueInStorage)); |
| 72 | let cachedHttp = new CachedHttp(this.mockStorage); |
| 73 | |
| 74 | let getRemoteValue = () => { |
| 75 | return Promise.resolve({ |
| 76 | parsedResponse: JSON.stringify("notexpected"), |
| 77 | request: undefined // We don't care about the request in the test |
nothing calls this directly
no test coverage detected