Merge pull request #1083 from Safelite/feature/CSR-1323
Update vins-by-image call for new endpoint.
This commit is contained in:
commit
21e9a8f5a3
3 changed files with 32 additions and 20 deletions
|
|
@ -7,16 +7,11 @@ import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
||||||
import { headerKeys } from "@/constants/header-keys";
|
import { headerKeys } from "@/constants/header-keys";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
callHttpClient({ method, endpoint, payload, logApiCall = true, isFormData = false }) {
|
callHttpClient({ method, endpoint, payload, logApiCall = true }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
|
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
|
||||||
let payloadAndAnalyticsData = {};
|
let payloadAndAnalyticsData = {};
|
||||||
if (isFormData) {
|
Object.assign(payloadAndAnalyticsData, payload, { AppName: "FixMyGlass" });
|
||||||
payloadAndAnalyticsData = payload;
|
|
||||||
payloadAndAnalyticsData.append("AppName", "FixMyGlass");
|
|
||||||
} else {
|
|
||||||
Object.assign(payloadAndAnalyticsData, payload, { AppName: "FixMyGlass" });
|
|
||||||
}
|
|
||||||
const headers = {
|
const headers = {
|
||||||
[headerKeys.EXPERIMENT]: JSON.stringify(store.getters.experimentSettings),
|
[headerKeys.EXPERIMENT]: JSON.stringify(store.getters.experimentSettings),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -531,13 +531,28 @@ export const actions = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
lookupVinByImage(context, image) {
|
lookupVinByImage(context, image) {
|
||||||
const data = new FormData();
|
return new Promise((resolve, reject) => {
|
||||||
data.append("vinImage", image);
|
let reader = new FileReader();
|
||||||
return globalMethods.callHttpClient({
|
reader.onload = (e) => {
|
||||||
method: endpoints.LookupVinByImage.method,
|
resolve(reader.result);
|
||||||
endpoint: endpoints.LookupVinByImage.url,
|
};
|
||||||
payload: data,
|
reader.readAsDataURL(image);
|
||||||
isFormData: true,
|
}).then((result) => {
|
||||||
|
const components = result.split(",");
|
||||||
|
const contentType = image.type;
|
||||||
|
const imageBase64 = components[1];
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
imageData: imageBase64,
|
||||||
|
contentType: contentType,
|
||||||
|
fileName: image.name,
|
||||||
|
};
|
||||||
|
|
||||||
|
return globalMethods.callHttpClient({
|
||||||
|
method: endpoints.LookupVinByImage.method,
|
||||||
|
endpoint: endpoints.LookupVinByImage.url,
|
||||||
|
payload: data,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
isVinByAddressPermissible(context, zip) {
|
isVinByAddressPermissible(context, zip) {
|
||||||
|
|
|
||||||
|
|
@ -406,14 +406,16 @@ describe("Actions", () => {
|
||||||
it("lookupVinByImage action, should return list of vins", async () => {
|
it("lookupVinByImage action, should return list of vins", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const context = state;
|
const context = state;
|
||||||
const dummyImage = {};
|
const image = new File([], "test.jpg", {
|
||||||
|
type: "image/jpeg",
|
||||||
|
});
|
||||||
|
|
||||||
globalMethods.callHttpClient.mockImplementation(() => {
|
globalMethods.callHttpClient.mockImplementation(() => {
|
||||||
return Promise.resolve({ data: ["1C6JJTAG3NL134044"] });
|
return Promise.resolve({ data: ["1C6JJTAG3NL134044"] });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const response = await actions.lookupVinByImage(context, dummyImage);
|
const response = await actions.lookupVinByImage(context, image);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(response.data).toEqual(["1C6JJTAG3NL134044"]);
|
expect(response.data).toEqual(["1C6JJTAG3NL134044"]);
|
||||||
|
|
@ -422,7 +424,9 @@ describe("Actions", () => {
|
||||||
it("lookupVinByImage action, should reject if error in calling API", async () => {
|
it("lookupVinByImage action, should reject if error in calling API", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const context = state;
|
const context = state;
|
||||||
const dummyImage = {};
|
const image = new File([], "test.jpg", {
|
||||||
|
type: "image/jpeg",
|
||||||
|
});
|
||||||
|
|
||||||
globalMethods.callHttpClient.mockImplementation(() => {
|
globalMethods.callHttpClient.mockImplementation(() => {
|
||||||
return Promise.reject("An error occurred");
|
return Promise.reject("An error occurred");
|
||||||
|
|
@ -431,9 +435,7 @@ describe("Actions", () => {
|
||||||
// Act
|
// Act
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
await expect(actions.lookupVinByImage(context, dummyImage)).rejects.toEqual(
|
await expect(actions.lookupVinByImage(context, image)).rejects.toEqual("An error occurred");
|
||||||
"An error occurred"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("getVehicleMakes action, should return makes list", async () => {
|
it("getVehicleMakes action, should return makes list", async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue