Skip to content

Commit

Permalink
Endpoints tests (#811)
Browse files Browse the repository at this point in the history
* All Assets

* Claimable Balances

* Effects + refactor endpoint URL template

* Fee Stats

* Ledgers

* Offers

* Operations

* Payments

* Transactions

* Update SDS

* Order book + asset object params

* Trade aggregations

* Fix PrettyJson records rendering

* Trades

* Cleanup

* Paths

* Liquidity pools

* Fix URL validation

* Cleanup

* Update reserves asset type

* Cleanup

* Endpoints tests

* Update asset validation

* openUrl helper
  • Loading branch information
quietbits authored Apr 5, 2024
1 parent ab6f2cf commit e940a79
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 34 deletions.
28 changes: 16 additions & 12 deletions src/app/(sidebar)/explore-endpoints/[[...pages]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { isEmptyObject } from "@/helpers/isEmptyObject";
import { sanitizeArray } from "@/helpers/sanitizeArray";
import { sanitizeObject } from "@/helpers/sanitizeObject";
import { parseJsonString } from "@/helpers/parseJsonString";
import { openUrl } from "@/helpers/openUrl";

import { Routes } from "@/constants/routes";
import { EXPLORE_ENDPOINTS_PAGES_HORIZON } from "@/constants/exploreEndpointsPages";
Expand Down Expand Up @@ -440,13 +441,17 @@ export default function ExploreEndpoints() {
<>
<div className="Endpoints__urlBar">
<Input
data-testid="endpoints-url"
id="endpoint-url"
fieldSize="md"
value={requestUrl}
readOnly
disabled
leftElement={
<div className="Endpoints__input__requestType">
<div
className="Endpoints__input__requestType"
data-testid="endpoints-url-method"
>
{pageData.requestMethod}
</div>
}
Expand All @@ -457,6 +462,7 @@ export default function ExploreEndpoints() {
type="submit"
disabled={!isSubmitEnabled()}
isLoading={isLoading || isFetching}
data-testid="endpoints-submitBtn"
>
Submit
</Button>
Expand Down Expand Up @@ -486,7 +492,7 @@ export default function ExploreEndpoints() {

return (
<div className="Endpoints__content">
<div className="PageBody__content">
<div className="PageBody__content" data-testid="endpoints-pageContent">
{renderPostPayload()}

{allFields.map((f) => {
Expand Down Expand Up @@ -616,7 +622,11 @@ export default function ExploreEndpoints() {
{page.label}
</Text>

<SdsLink href={pageData.docsUrl} icon={<Icon.LinkExternal01 />}>
<SdsLink
href={pageData.docsUrl}
icon={<Icon.LinkExternal01 />}
data-testid="endpoints-docsLink"
>
{`View ${pageData.docsLabel ? `${pageData.docsLabel} ` : ""}documentation`}
</SdsLink>
</div>
Expand Down Expand Up @@ -703,10 +713,7 @@ const ExploreEndpointsLandingPage = () => {
buttonLabel: "See docs",
buttonIcon: <Icon.LinkExternal01 />,
buttonAction: () =>
window.open(
"https://developers.stellar.org/network/soroban-rpc/methods",
"_blank",
),
openUrl("https://developers.stellar.org/network/soroban-rpc/methods"),
},
{
id: "horizon",
Expand All @@ -715,10 +722,7 @@ const ExploreEndpointsLandingPage = () => {
buttonLabel: "See docs",
buttonIcon: <Icon.LinkExternal01 />,
buttonAction: () =>
window.open(
"https://developers.stellar.org/network/horizon/resources",
"_blank",
),
openUrl("https://developers.stellar.org/network/horizon/resources"),
},
];

Expand Down Expand Up @@ -751,7 +755,7 @@ const ExploreEndpointsLandingPage = () => {

<Text size="sm" as="p">
For Stellar docs, take a look at the{" "}
<Link href="https://developers.stellar.org/docs">
<Link href="https://developers.stellar.org/">
Stellar developers site
</Link>
.
Expand Down
18 changes: 7 additions & 11 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
"use client";

import { useRouter } from "next/navigation";
import { Card, Link, Text, Icon } from "@stellar/design-system";

import { NextLink } from "@/components/NextLink";
import { LayoutContentContainer } from "@/components/layout/LayoutContentContainer";
import { InfoCards } from "@/components/InfoCards";
import { SdsLink } from "@/components/SdsLink";
import { Routes } from "@/constants/routes";
import { openUrl } from "@/helpers/openUrl";

export default function Introduction() {
const router = useRouter();

const infoCards = [
{
id: "stellar-quest",
Expand All @@ -20,7 +18,7 @@ export default function Introduction() {
"Learn to build world-class applications on the Stellar network in a gamified experience",
buttonLabel: "Go to site",
buttonIcon: <Icon.LinkExternal01 />,
buttonAction: () => window.open("https://quest.stellar.org/", "_blank"),
buttonAction: () => openUrl("https://quest.stellar.org/"),
},
{
id: "tools",
Expand All @@ -29,7 +27,8 @@ export default function Introduction() {
"Tools, like the Stellar CLI, for reading and interacting with smart contracts on the Stellar Network",
buttonLabel: "See tools",
buttonIcon: undefined,
buttonAction: () => router.push(Routes.SOROBAN_CONTRACT_EXPLORER),
buttonAction: () =>
openUrl("https://developers.stellar.org/docs/tools/sdks"),
},
{
id: "stellar-rpc",
Expand All @@ -38,10 +37,7 @@ export default function Introduction() {
buttonLabel: "Go to docs",
buttonIcon: <Icon.LinkExternal01 />,
buttonAction: () =>
window.open(
"https://developers.stellar.org/network/soroban-rpc",
"_blank",
),
openUrl("https://developers.stellar.org/network/soroban-rpc"),
},
{
id: "horizon",
Expand All @@ -51,7 +47,7 @@ export default function Introduction() {
buttonLabel: "Go to docs",
buttonIcon: <Icon.LinkExternal01 />,
buttonAction: () =>
window.open("https://developers.stellar.org/network/horizon", "_blank"),
openUrl("https://developers.stellar.org/network/horizon"),
},
];

Expand Down Expand Up @@ -83,7 +79,7 @@ export default function Introduction() {

<Text size="sm" as="p">
For Stellar docs, take a look at the{" "}
<Link href="https://developers.stellar.org/docs">
<Link href="https://developers.stellar.org/">
Stellar developers site
</Link>
.
Expand Down
2 changes: 1 addition & 1 deletion src/components/MainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const primaryNavLinks: NavLink[] = [

const secondaryNavLinks: NavLink[] = [
{
href: "https://developers.stellar.org/network",
href: "https://developers.stellar.org/",
label: "View Documentation",
},
];
Expand Down
14 changes: 12 additions & 2 deletions src/components/layout/LayoutSidebarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ export const LayoutSidebarContent = ({
<div
className="LabLayout__sidebar__section"
key={`sidebar-${index}`}
data-testid="endpoints-sidebar-section"
>
{sidebar.instruction ? (
<div className="LabLayout__sidebar__instruction">
<div
className="LabLayout__sidebar__instruction"
data-testid="endpoints-sidebar-subtitle"
>
{sidebar.instruction}
</div>
) : null}
Expand Down Expand Up @@ -95,12 +99,16 @@ const Link = ({ item, pathname }: { item: SidebarLink; pathname: string }) => {

if (item.nestedItems?.length) {
return (
<div className="SidebarLink--nested">
<div
className="SidebarLink--nested"
data-testid={`endpoints-sidebar${item.route}`}
>
<div
className="SidebarLink SidebarLink__toggle"
onClick={() => {
setIsExpanded(!isExpanded);
}}
data-testid="endpoints-sidebar-linkToggle"
>
<Icon.ChevronRight /> {item.label}
</div>
Expand All @@ -109,6 +117,7 @@ const Link = ({ item, pathname }: { item: SidebarLink; pathname: string }) => {
<div
className="SidebarLink__nestedItemsWrapper"
data-is-expanded={isExpanded}
data-testid="endpoints-sidebar-linksContainer"
>
<div className="SidebarLink__nestedItems">
{item.nestedItems.map((nested) => (
Expand All @@ -117,6 +126,7 @@ const Link = ({ item, pathname }: { item: SidebarLink; pathname: string }) => {
href={nested.route}
className="SidebarLink"
data-is-active={pathname === nested.route}
data-testid="endpoints-sidebar-link"
>
{nested.label}
</NextLink>
Expand Down
4 changes: 2 additions & 2 deletions src/constants/exploreEndpointsPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const EXPLORE_ENDPOINTS_PAGES_HORIZON: ExploreEndpointsPagesProps = {
form: {
docsUrl:
"https://developers.stellar.org/network/horizon/resources/list-all-claimable-balances",
docsLabel: "claimable balance",
docsLabel: "claimable balances",
requestMethod: "GET",
endpointUrlTemplate:
"/claimable_balances/{?sponsor,asset,claimant,cursor,limit,order}",
Expand All @@ -108,7 +108,7 @@ export const EXPLORE_ENDPOINTS_PAGES_HORIZON: ExploreEndpointsPagesProps = {
form: {
docsUrl:
"https://developers.stellar.org/network/horizon/resources/retrieve-a-claimable-balance",
docsLabel: "claimable balances",
docsLabel: "claimable balance",
requestMethod: "GET",
endpointUrlTemplate: "/claimable_balances/{claimable_balance_id}",
requiredParams: "claimable_balance_id",
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/openUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const openUrl = (url: string) => {
return window.open(url, "_blank", "noopener,noreferrer");
};
9 changes: 3 additions & 6 deletions src/validate/methods/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { assetCode } from "./assetCode";
import { publicKey } from "./publicKey";
import { AssetObjectValue } from "@/types/types";

export const asset = (
asset: AssetObjectValue | undefined,
isRequired?: boolean,
) => {
export const asset = (asset: AssetObjectValue | undefined) => {
if (asset?.type && asset.type === "native") {
return false;
}

const invalid = Object.entries({
code: assetCode(asset?.code || "", asset?.type, isRequired),
issuer: publicKey(asset?.issuer || "", isRequired),
code: assetCode(asset?.code || "", asset?.type),
issuer: publicKey(asset?.issuer || ""),
}).reduce((res, cur) => {
const [key, value] = cur;

Expand Down
Loading

0 comments on commit e940a79

Please sign in to comment.