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 car-9732
Browse files Browse the repository at this point in the history
  • Loading branch information
Marine-Berthier authored Feb 28, 2022
2 parents 33ab0ff + 95b5ce5 commit 1f29369
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 18 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
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"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",
"@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 @@ -372,3 +374,11 @@ export {
saveFavourites,
deleteFavourite,
} from "./services/favourites"

export {
createListingComparison,
deleteListingComparison,
fetchListingComparison,
fetchListingComparisons,
updateListingComparison,
} from "./services/listingComparisons"
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 },
})
}
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 1f29369

Please sign in to comment.