Fixed logic in getAvailabilityRating
This commit is contained in:
parent
97ca23bc93
commit
2a89764989
2 changed files with 70 additions and 127 deletions
|
|
@ -62,31 +62,10 @@ export async function getAvailabilityRating(
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(shopTimeSlots)
|
|
||||||
|
|
||||||
// Rate the availability for the shop
|
|
||||||
let numberOfAppointmentsPerDay = [];
|
|
||||||
for (let i = 0; i < shopTimeSlots.data.days.length; i++) {
|
|
||||||
numberOfAppointmentsPerDay.push(shopTimeSlots.data.days[i].timeSlots.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(numberOfAppointmentsPerDay)
|
|
||||||
|
|
||||||
const dateRange = 7;
|
|
||||||
const minimumNumberOfAppointmentsPerDay = 1;
|
|
||||||
const numberOfDaysToEvaluate = 2;
|
const numberOfDaysToEvaluate = 2;
|
||||||
|
const isGoodAvailability =
|
||||||
let daysWithMinimalAppointmentsCount = 0;
|
shopTimeSlots.data.days.filter((x) => x.timeSlots.length > 0).length >=
|
||||||
for (let i = 0; i < dateRange; i++) {
|
numberOfDaysToEvaluate;
|
||||||
if (numberOfAppointmentsPerDay[i] >= minimumNumberOfAppointmentsPerDay) {
|
|
||||||
daysWithMinimalAppointmentsCount++;
|
|
||||||
if (daysWithMinimalAppointmentsCount >= numberOfDaysToEvaluate) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const isGoodAvailability = daysWithMinimalAppointmentsCount >= numberOfDaysToEvaluate;
|
|
||||||
|
|
||||||
const shopStatus = isGoodAvailability ? "high" : "low";
|
const shopStatus = isGoodAvailability ? "high" : "low";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,94 +92,54 @@ const mockStoreActionGetServiceabilityDetails = storeActions.GET_SERVICEABILITY_
|
||||||
const mockStoreActionGetShopTimeSlots = storeActions.GET_SHOP_TIME_SLOTS;
|
const mockStoreActionGetShopTimeSlots = storeActions.GET_SHOP_TIME_SLOTS;
|
||||||
|
|
||||||
const mockGetShopTimeSlotsGoodAvailability = {
|
const mockGetShopTimeSlotsGoodAvailability = {
|
||||||
estimatedServiceMinutesMinimum: 0,
|
data: {
|
||||||
estimatedServiceMinutesMaximimum: 0,
|
estimatedServiceMinutesMinimum: 0,
|
||||||
days: [
|
estimatedServiceMinutesMaximimum: 0,
|
||||||
{
|
days: [
|
||||||
date: "string",
|
{
|
||||||
timeSlots: [
|
date: "string",
|
||||||
{
|
timeSlots: [
|
||||||
id: "string",
|
{
|
||||||
startTime: "",
|
id: "string",
|
||||||
endTime: "",
|
startTime: "",
|
||||||
offerPremium: true,
|
endTime: "",
|
||||||
},
|
offerPremium: true,
|
||||||
],
|
},
|
||||||
},
|
],
|
||||||
{
|
},
|
||||||
date: "string",
|
{
|
||||||
timeSlots: [],
|
date: "string",
|
||||||
},
|
timeSlots: [
|
||||||
{
|
{
|
||||||
date: "string",
|
id: "string",
|
||||||
timeSlots: [],
|
startTime: "",
|
||||||
},
|
endTime: "",
|
||||||
{
|
offerPremium: true,
|
||||||
date: "string",
|
},
|
||||||
timeSlots: [],
|
],
|
||||||
},
|
},
|
||||||
{
|
],
|
||||||
date: "string",
|
}
|
||||||
timeSlots: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: "string",
|
|
||||||
timeSlots: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: "string",
|
|
||||||
timeSlots: [
|
|
||||||
{
|
|
||||||
id: "string",
|
|
||||||
startTime: "",
|
|
||||||
endTime: "",
|
|
||||||
offerPremium: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockGetShopTimeSlotsLowAvailability = {
|
const mockGetShopTimeSlotsLowAvailability = {
|
||||||
estimatedServiceMinutesMinimum: 0,
|
data: {
|
||||||
estimatedServiceMinutesMaximimum: 0,
|
estimatedServiceMinutesMinimum: 0,
|
||||||
days: [
|
estimatedServiceMinutesMaximimum: 0,
|
||||||
{
|
days: [
|
||||||
date: "string",
|
{
|
||||||
timeSlots: [],
|
date: "string",
|
||||||
},
|
timeSlots: [
|
||||||
{
|
{
|
||||||
date: "string",
|
id: "string",
|
||||||
timeSlots: [],
|
startTime: "",
|
||||||
},
|
endTime: "",
|
||||||
{
|
offerPremium: true,
|
||||||
date: "string",
|
},
|
||||||
timeSlots: [],
|
],
|
||||||
},
|
},
|
||||||
{
|
],
|
||||||
date: "string",
|
}
|
||||||
timeSlots: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: "string",
|
|
||||||
timeSlots: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: "string",
|
|
||||||
timeSlots: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: "string",
|
|
||||||
timeSlots: [
|
|
||||||
{
|
|
||||||
id: "string",
|
|
||||||
startTime: "",
|
|
||||||
endTime: "",
|
|
||||||
offerPremium: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock("@/mixins/base-mixin.js", () => ({
|
jest.mock("@/mixins/base-mixin.js", () => ({
|
||||||
|
|
@ -228,6 +188,7 @@ jest.mock("@/mixins/base-mixin.js", () => ({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionName === mockStoreActionGetShopTimeSlots) {
|
if (actionName === mockStoreActionGetShopTimeSlots) {
|
||||||
|
console.log(request)
|
||||||
if (request.providerNumber == "0000001") {
|
if (request.providerNumber == "0000001") {
|
||||||
return Promise.resolve(mockGetShopTimeSlotsGoodAvailability);
|
return Promise.resolve(mockGetShopTimeSlotsGoodAvailability);
|
||||||
}
|
}
|
||||||
|
|
@ -310,23 +271,26 @@ describe("service-location-helper.js", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getAvailabilityRating", () => {
|
describe("getAvailabilityRating", () => {
|
||||||
// it("Should return a 'Good' rating", async () => {
|
it("Should return a 'high' rating", async () => {
|
||||||
// // Arrange
|
// Arrange
|
||||||
// const providerNumber = "0000001";
|
const providerNumber = "0000001";
|
||||||
// const expected = "Good";
|
const expected = "high";
|
||||||
// // Act
|
// Act
|
||||||
// const result = await getAvailabilityRating(providerNumber);
|
const result = await getAvailabilityRating("2023-06-30", "2023-07-06", "Inshop", providerNumber);
|
||||||
// // Assert
|
|
||||||
// expect(result).toEqual(expected);
|
// Assert
|
||||||
// });
|
expect(result).toEqual(expected);
|
||||||
// it("Should return a 'Low' rating", async () => {
|
});
|
||||||
// // Arrange
|
|
||||||
// const providerNumber = "0000000";
|
it("Should return a 'low' rating", async () => {
|
||||||
// const expected = "Low";
|
// Arrange
|
||||||
// // Act
|
const providerNumber = "0000000";
|
||||||
// const result = await getAvailabilityRating(providerNumber);
|
const expected = "low";
|
||||||
// // Assert
|
// Act
|
||||||
// expect(result).toEqual(expected);
|
const result = await getAvailabilityRating("2023-06-30", "2023-07-06", "Inshop", providerNumber);
|
||||||
// });
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue