This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
3,113 additions
and
4,052 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}) | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type ListingComparison = { | ||
id: number | ||
name: string | ||
listingIds: number[] | ||
} |