Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into car9676
Browse files Browse the repository at this point in the history
  • Loading branch information
ufkaya authored Mar 3, 2022
2 parents 72ceffa + 799c713 commit 0422835
Show file tree
Hide file tree
Showing 14 changed files with 3,113 additions and 4,052 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ Also accompanying modes and param types, as well as default values, are exported
- [`saveFavourite`](https://internal.carforyou.dev/api-docs/swagger-ui/?urls.primaryName=buyer-service#/User%20Favorite%20Listing/create)
- [`saveFavourites`](https://internal.carforyou.dev/api-docs/swagger-ui/?urls.primaryName=buyer-service#/User%20Favorite%20Listing/bulkCreate)
- [`deleteFavourite](https://internal.carforyou.dev/api-docs/swagger-ui/?urls.primaryName=buyer-service#/User%20Favorite%20Listing/delete)
- [Listing comparisons](https://internal.carforyou.dev/api-docs/swagger-ui/#/User%20Listing%20Comparison)
- [`fetchListingComparisons`](https://internal.carforyou.dev/api-docs/swagger-ui/#/User%20Listing%20Comparison/getAll)
- [`fetchListingComparison`](https://internal.carforyou.dev/api-docs/swagger-ui/#/User%20Listing%20Comparison/get)
- [`createListingComparison`](https://internal.carforyou.dev/api-docs/swagger-ui/#/User%20Listing%20Comparison/create)
- [`updateListingComparison`](https://internal.carforyou.dev/api-docs/swagger-ui/#/User%20Listing%20Comparison/update)
- [`deleteListingComparison`](https://internal.carforyou.dev/api-docs/swagger-ui/#/User%20Listing%20Comparison/delete)
- [Leasing](https://buyer-service.preprod.carforyou.ch/swagger-ui/index.html#/Leasing%20Interest)
- [`createLeasingInterest`](https://buyer-service.preprod.carforyou.ch/swagger-ui/index.html#/Leasing%20Interest/createUsingPOST)
- [`calculateLeasing`](https://listing-enrichment-service.preprod.carforyou.ch/swagger-ui/index.html#/Listing/calculateLeasingUsingPOST)
Expand Down
6,930 changes: 2,894 additions & 4,036 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"license": "MIT",
"homepage": "https://github.com/autoricardo/carforyou-api-client-pkg#readme",
"devDependencies": {
"@carforyou/eslint-config": "4.0.12",
"@types/jest": "27.4.0",
"@types/node": "16.11.25",
"@carforyou/eslint-config": "4.0.14",
"@types/jest": "27.4.1",
"@types/node": "16.11.26",
"jest": "27.5.1",
"jest-fetch-mock": "3.0.3",
"rimraf": "3.0.2",
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export {
BulkFetchResponse,
} from "./types/models/index"

export { ListingComparison } from "./types/models/listingComparison"

export { BuyNowApplication } from "./types/models/applications"

export { LoanInterest, LoanCalculation } from "./types/models/loan"
Expand Down Expand Up @@ -373,3 +375,11 @@ export {
saveFavourites,
deleteFavourite,
} from "./services/favourites"

export {
createListingComparison,
deleteListingComparison,
fetchListingComparison,
fetchListingComparisons,
updateListingComparison,
} from "./services/listingComparisons"
4 changes: 2 additions & 2 deletions src/lib/__tests__/dateEncoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { decodeDate, encodeDate } from "../dateEncoding"
describe("dateEncoding", () => {
describe("#encodeDate", () => {
it("returs null without a year", () => {
expect(encodeDate({})).toBe(null)
expect(encodeDate({ year: null, month: null })).toBe(null)
})

it("defaults month to january if only year is provided", () => {
expect(encodeDate({ year: 1988 })).toEqual("1988-01-01")
expect(encodeDate({ year: 1988, month: null })).toEqual("1988-01-01")
})

it("converts date to YYYY-MM-DD format", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dateEncoding.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Date as DateType } from "../types/models"

export const encodeDate = (date: DateType = {}) => {
export const encodeDate = (date: DateType) => {
if (!date) {
return null
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib/factories/__tests__/listing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe("listing", () => {
consumptionCombined: "consumptionCombined",
consumptionExtraUrban: "consumptionExtraUrban",
consumptionUrban: "consumptionUrban",
systemPerformanceKiloWatts: "systemPerformanceKiloWatts",
batteryCapacity: "batteryCapacity",
powerConsumption: "powerConsumption",
range: "range",
Expand Down Expand Up @@ -57,7 +56,6 @@ describe("listing", () => {
"consumptionCombined",
"consumptionExtraUrban",
"consumptionUrban",
"systemPerformanceKiloWatts",
"horsePower",
"cubicCapacity",
"cylinders",
Expand Down
4 changes: 0 additions & 4 deletions src/lib/factories/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const defaults: ListingType = {
frameNumber: "123456",
serialNumber: "123456",
tsn: "1234567890",
systemPerformanceKiloWatts: null,
directImport: false,
hasAdditionalTyres: true,
hasRoofRack: false,
Expand Down Expand Up @@ -235,7 +234,6 @@ export function EmptyListing(): ListingType {
consumptionCombined: undefined,
consumptionExtraUrban: undefined,
consumptionUrban: undefined,
systemPerformanceKiloWatts: undefined,
transmissionType: undefined,
horsePower: undefined,
driveType: undefined,
Expand Down Expand Up @@ -350,7 +348,6 @@ export function ListingFromType({
consumptionCombined,
consumptionExtraUrban,
consumptionUrban,
systemPerformanceKiloWatts,
batteryCapacity,
powerConsumption,
range,
Expand Down Expand Up @@ -393,7 +390,6 @@ export function ListingFromType({
consumptionCombined: consumptionCombined || undefined,
consumptionExtraUrban: consumptionExtraUrban || undefined,
consumptionUrban: consumptionUrban || undefined,
systemPerformanceKiloWatts: systemPerformanceKiloWatts || undefined,
batteryCapacity: batteryCapacity || undefined,
powerConsumption: powerConsumption || undefined,
range: range || undefined,
Expand Down
1 change: 0 additions & 1 deletion src/lib/factories/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const detailsDefaults: TypeType = {
consumptionCombined: 8.4,
consumptionExtraUrban: 6.6,
consumptionUrban: 11.6,
systemPerformanceKiloWatts: 13.4,
batteryCapacity: 100,
powerConsumption: 90,
range: 153,
Expand Down
103 changes: 103 additions & 0 deletions src/services/__tests__/listingComparisons.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import {
createListingComparison,
deleteListingComparison,
fetchListingComparison,
fetchListingComparisons,
updateListingComparison,
} from "../listingComparisons"

describe("Listing comparisons", () => {
beforeEach(fetchMock.mockClear)

const options = { accessToken: "Let me in, please." }

describe("fetchListingComparisons", () => {
it("calls the api", async () => {
await fetchListingComparisons({
options,
})

expect(fetch).toHaveBeenCalledWith(
"test.gateway/users/me/listing-comparisons?sort=auditMetadata.createdDate,desc",
expect.any(Object)
)
})
})

describe("fetchListingComparison", () => {
it("calls the api", async () => {
await fetchListingComparison({
id: 1,
options,
})

expect(fetch).toHaveBeenCalledWith(
"test.gateway/users/me/listing-comparisons/1",
expect.any(Object)
)
})
})

describe("createListingComparison", () => {
it("calls the api", async () => {
await createListingComparison({
listingComparison: {
name: "foo",
listingIds: [1, 2, 3],
},
options,
})

expect(fetch).toHaveBeenCalledWith(
"test.gateway/users/me/listing-comparisons",
expect.objectContaining({
method: "POST",
body: JSON.stringify({
name: "foo",
listingIds: [1, 2, 3],
}),
})
)
})
})

describe("updateListingComparison", () => {
it("calls the api", async () => {
await updateListingComparison({
listingComparison: {
name: "foo",
listingIds: [1, 2, 3],
id: 1,
},
options,
})

expect(fetch).toHaveBeenCalledWith(
"test.gateway/users/me/listing-comparisons/1",
expect.objectContaining({
method: "PUT",
body: JSON.stringify({
name: "foo",
listingIds: [1, 2, 3],
}),
})
)
})
})

describe("deleteListingComparison", () => {
it("calls the api", async () => {
await deleteListingComparison({
id: 1,
options,
})

expect(fetch).toHaveBeenCalledWith(
"test.gateway/users/me/listing-comparisons/1",
expect.objectContaining({
method: "DELETE",
})
)
})
})
})
87 changes: 87 additions & 0 deletions src/services/listingComparisons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { ListingComparison } from "../types/models/listingComparison"
import {
ApiCallOptions,
deletePath,
fetchPath,
handleValidationError,
postData,
putData,
} from "../base"
import { Paginated, WithValidationError } from ".."

export const fetchListingComparisons = async ({
options = {},
}: {
options: ApiCallOptions
}): Promise<Paginated<ListingComparison>> => {
return fetchPath({
path: "users/me/listing-comparisons?sort=auditMetadata.createdDate,desc",
options: { isAuthorizedRequest: true, ...options },
})
}

export const fetchListingComparison = async ({
id,
options = {},
}: {
id: number
options: ApiCallOptions
}): Promise<ListingComparison> => {
return fetchPath({
path: `users/me/listing-comparisons/${id}`,
options: { isAuthorizedRequest: true, ...options },
})
}

export const createListingComparison = async ({
listingComparison,
options = {},
}: {
listingComparison: Omit<ListingComparison, "id">
options: ApiCallOptions
}): Promise<WithValidationError<{ id: number }>> => {
try {
const result = await postData({
path: "/users/me/listing-comparisons",
body: listingComparison,
options: { isAuthorizedRequest: true, ...options },
})

return { tag: "success", result }
} catch (error) {
return handleValidationError(error)
}
}

export const updateListingComparison = async ({
listingComparison: { id, ...data },
options = {},
}: {
listingComparison: ListingComparison
options: ApiCallOptions
}): Promise<WithValidationError<{ ok: true }>> => {
try {
await putData({
path: `/users/me/listing-comparisons/${id}`,
body: data,
options: { isAuthorizedRequest: true, ...options },
})

return { tag: "success", result: { ok: true } }
} catch (error) {
return handleValidationError(error)
}
}

export const deleteListingComparison = async ({
id,
options = {},
}: {
id: number
options: ApiCallOptions
}): Promise<void> => {
await deletePath({
path: `/users/me/listing-comparisons/${id}`,
options: { isAuthorizedRequest: true, ...options },
})
}
1 change: 0 additions & 1 deletion src/types/models/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface EnergyListingTypeCommons {
consumptionExtraUrban: number
consumptionUrban: number

systemPerformanceKiloWatts: number
batteryCapacity: number
powerConsumption: number
range: number
Expand Down
4 changes: 2 additions & 2 deletions src/types/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ export interface SearchWhatsappLead extends SearchLeads {
}

export interface Date {
month?: number
year?: number
month: number
year: number
}

export interface PresignedUrl {
Expand Down
5 changes: 5 additions & 0 deletions src/types/models/listingComparison.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type ListingComparison = {
id: number
name: string
listingIds: number[]
}

0 comments on commit 0422835

Please sign in to comment.