cronofy-elements
Advanced tools
Comparing version 1.9.0 to 1.9.1
{ | ||
"name": "cronofy-elements", | ||
"version": "1.9.0", | ||
"version": "1.9.1", | ||
"description": "Fast track scheduling with Cronofy's embeddable UI Elements", | ||
@@ -62,3 +62,3 @@ "main": "build/npm/CronofyElements.js", | ||
"express": "^4.16.4", | ||
"file-loader": "^1.1.11", | ||
"file-loader": "^5.0.2", | ||
"git-revision-webpack-plugin": "^3.0.3", | ||
@@ -65,0 +65,0 @@ "jest": "^24.9.0", |
@@ -107,3 +107,3 @@ import React, { useState, useEffect } from "react"; | ||
.then(res => { | ||
const isNewRule = res[0].unknownRule ? true : false; | ||
const isNewRule = res[0].type === 404; | ||
const rulesResponse = isNewRule | ||
@@ -110,0 +110,0 @@ ? buildRuleTemplate(options) |
@@ -26,2 +26,11 @@ import * as mocks from "./mocks"; | ||
}; | ||
const handleInvalidRulesResponse = res => { | ||
if (res.status !== 200 && res.status !== 422 && res.status !== 404) { | ||
throw { | ||
type: res.status, | ||
message: errorMessages[res.status].message | ||
}; | ||
} | ||
return res; | ||
}; | ||
@@ -235,10 +244,9 @@ const catchAndRethrowErrors = error => { | ||
}) | ||
.then(handleInvalidRulesResponse) | ||
.then(res => { | ||
if (res.status === 404) { | ||
return { unknownRule: true }; | ||
return { type: 404 }; | ||
} | ||
return res; | ||
return res.json(); | ||
}) | ||
.then(handleInvalidResponses) | ||
.then(res => res.json()) | ||
.catch(catchAndRethrowErrors); | ||
@@ -245,0 +253,0 @@ }; |
@@ -493,3 +493,3 @@ // import fetchMock from "fetch-mock"; | ||
// Injects the correct error message | ||
// Injects an error message | ||
await connections | ||
@@ -501,2 +501,45 @@ .getAvailability(...exampleOptions, args) | ||
}); | ||
// getAvailabilityRules | ||
it("handles fetch availability_rule request", async () => { | ||
const mockBody = { | ||
availability_rule: { | ||
availability_rule_id: "availability_rule_id", | ||
tzid: "Europe/London", | ||
weekly_periods: [{}, {}, {}, {}, {}] | ||
} | ||
}; | ||
fetch.mockResponseOnce(JSON.stringify(mockBody)); | ||
const res = await connections.getAvailabilityRules( | ||
...exampleOptions, | ||
"availability_rule_id" | ||
); | ||
expect(res).toEqual(mockBody); | ||
}); | ||
// getAvailabilityRules | ||
it("handles failed fetch availability_rule request", async () => { | ||
fetch.mockReject(new Error("unknown error")); | ||
// Injects an error message | ||
await connections | ||
.getAvailabilityRules(...exampleOptions, "availability_rule_id") | ||
.catch(err => { | ||
expect(typeof err.message).toEqual("string"); | ||
}); | ||
}); | ||
// getAvailabilityRules | ||
it("handles unknown availability_rule requests", async () => { | ||
fetch.mockResponseOnce(JSON.stringify([]), { status: 404 }); | ||
const res = await connections.getAvailabilityRules( | ||
...exampleOptions, | ||
"availability_rule_id" | ||
); | ||
expect(res.type).toEqual(404); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2459492
21453
48