Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust trailing slash for API call in frontend #244

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/account/home/PaymentsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const payments = computed(() => {

<template #item.actions="{ row }">
<ButtonLink
:to="`/webapi/download/receipt/${row.identifier}`"
:to="`/webapi/download/receipt/${row.identifier}/`"
color="primary"
external
>
Expand Down
10 changes: 5 additions & 5 deletions store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@

try {
const response = await fetchWithCsrf<ActionResultResponse>(
`/webapi/subscription/${subscription.identifier}`,
`/webapi/subscription/${subscription.identifier}/`,
{
method: 'DELETE',
},
Expand Down Expand Up @@ -327,7 +327,7 @@
const checkout = async (plan: number): Promise<Result<CardCheckout>> => {
try {
const response = await fetchWithCsrf<CardCheckoutResponse>(
`/webapi/checkout/card/${plan}`,
`/webapi/checkout/card/${plan}/`,
{
method: 'GET',
},
Expand All @@ -352,7 +352,7 @@
): Promise<Result<true, PaymentError>> => {
try {
const response = await fetchWithCsrf<ActionResultResponse>(
'/webapi/payment/btr',
'/webapi/payment/btr/',
{
body: request,
method: 'POST',
Expand Down Expand Up @@ -396,7 +396,7 @@
): Promise<Result<CryptoPayment, PaymentError>> => {
try {
const response = await fetchWithCsrf<CryptoPaymentResponse>(
'/webapi/payment/crypto',
'/webapi/payment/crypto/',
{
body: convertKeys(
{
Expand Down Expand Up @@ -444,7 +444,7 @@
): Promise<Result<PendingCryptoPayment>> => {
try {
const response = await fetchWithCsrf<PendingCryptoPaymentResponse>(
'/webapi/payment/pending',
'/webapi/payment/pending/',
{
params: convertKeys({ subscriptionId }, false, false),
},
Expand Down Expand Up @@ -564,7 +564,7 @@
const { start: startCountdown, stop: stopCountdown } = useTimeoutFn(
async () => {
logger.debug('session expired, logging out');
await logout();

Check warning on line 567 in store/index.ts

View workflow job for this annotation

GitHub Actions / ci

'logout' was used before it was defined
},
SESSION_TIMEOUT,
);
Expand Down
8 changes: 4 additions & 4 deletions store/payments/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const usePaymentCardsStore = defineStore('payments/cards', () => {
const getCard = async (): Promise<void> => {
try {
const response = await fetchWithCsrf<SavedCardResponse>(
'/webapi/payment/btr/cards',
'/webapi/payment/btr/cards/',
{
method: 'GET',
},
Expand All @@ -34,7 +34,7 @@ export const usePaymentCardsStore = defineStore('payments/cards', () => {
const addCard = async (request: CreateCardRequest): Promise<string> => {
try {
const response = await fetchWithCsrf<SavedCard>(
'/webapi/payment/btr/cards',
'/webapi/payment/btr/cards/',
{
body: request,
method: 'POST',
Expand All @@ -52,7 +52,7 @@ export const usePaymentCardsStore = defineStore('payments/cards', () => {
const deleteCard = async (token: string): Promise<void> => {
try {
await fetchWithCsrf<ApiResponse<boolean>>(
'/webapi/payment/btr/cards',
'/webapi/payment/btr/cards/',
{
body: { paymentToken: token },
method: 'DELETE',
Expand All @@ -68,7 +68,7 @@ export const usePaymentCardsStore = defineStore('payments/cards', () => {
const createCardNonce = async (request: CreateCardNonceRequest): Promise<string> => {
try {
const response = await fetchWithCsrf<CreateCardNonceResponse>(
'/webapi/payment/btr/cards/nonce',
'/webapi/payment/btr/cards/nonce/',
{
body: request,
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion store/payments/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const usePaymentCryptoStore = defineStore('payments/crypto', () => {
const fetchPaymentAssets = async (): Promise<void> => {
set(paymentAssetsLoading, true);
try {
const response = await fetchWithCsrf<PaymentAssetResponse>('/webapi/payment/crypto/options', {
const response = await fetchWithCsrf<PaymentAssetResponse>('/webapi/payment/crypto/options/', {
method: 'GET',
});
set(paymentAssets, PaymentAssetResponse.parse(response));
Expand Down
8 changes: 4 additions & 4 deletions store/payments/paypal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const usePaymentPaypalStore = defineStore('payments/paypal', () => {
const getPaypal = async (): Promise<void> => {
try {
const response = await fetchWithCsrf<SavedPaypalResponse>(
'/webapi/payment/btr/paypal',
'/webapi/payment/btr/paypal/',
{
method: 'GET',
},
Expand All @@ -34,7 +34,7 @@ export const usePaymentPaypalStore = defineStore('payments/paypal', () => {
const addPaypal = async (request: VaultPaypalRequest): Promise<string> => {
try {
const response = await fetchWithCsrf<SavedPaypalAccount>(
'/webapi/payment/btr/paypal',
'/webapi/payment/btr/paypal/',
{
body: request,
method: 'POST',
Expand All @@ -52,7 +52,7 @@ export const usePaymentPaypalStore = defineStore('payments/paypal', () => {
const deletePaypal = async (token: string): Promise<void> => {
try {
await fetchWithCsrf<ApiResponse<boolean>>(
'/webapi/payment/btr/paypal',
'/webapi/payment/btr/paypal/',
{
body: { paymentToken: token },
method: 'DELETE',
Expand All @@ -68,7 +68,7 @@ export const usePaymentPaypalStore = defineStore('payments/paypal', () => {
const createPaypalNonce = async (request: CreatePaypalNonceRequest): Promise<string> => {
try {
const response = await fetchWithCsrf<CreatePaypalNonceResponse>(
'/webapi/payment/btr/paypal/nonce',
'/webapi/payment/btr/paypal/nonce/',
{
body: request,
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/specs/pages/signup.spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('signup test', () => {
});

beforeEach(() => {
cy.intercept('/webapi/countries', {
cy.intercept('/webapi/countries/', {
body: {
result: [{ code: 'CT', name: 'Country' }],
},
Expand Down
18 changes: 9 additions & 9 deletions tests/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import { HttpResponse, http } from 'msw';
const { BACKEND_URL } = import.meta.env;

export const handlers = [
http.options(`${BACKEND_URL}/webapi/csrf`, () => HttpResponse.json({}, {
http.options(`${BACKEND_URL}/webapi/csrf/`, () => HttpResponse.json({}, {
headers: {
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
'Access-Control-Allow-Origin': '*',
},
})),
http.options(`${BACKEND_URL}/webapi/countries`, () => HttpResponse.json({}, {
http.options(`${BACKEND_URL}/webapi/countries/`, () => HttpResponse.json({}, {
headers: {
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
'Access-Control-Allow-Origin': '*',
},
})),
http.options(`${BACKEND_URL}/webapi/login`, () => HttpResponse.json({}, {
http.options(`${BACKEND_URL}/webapi/login/`, () => HttpResponse.json({}, {
headers: {
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
'Access-Control-Allow-Origin': '*',

},
})),
http.options(`${BACKEND_URL}/webapi/account`, () => HttpResponse.json({}, {
http.options(`${BACKEND_URL}/webapi/account/`, () => HttpResponse.json({}, {
headers: {
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
'Access-Control-Allow-Origin': '*',
},
})),
http.get(`${BACKEND_URL}/webapi/csrf`, () =>
http.get(`${BACKEND_URL}/webapi/csrf/`, () =>
HttpResponse.json(
{
message: 'CSRF cookie set',
Expand All @@ -39,16 +39,16 @@ export const handlers = [
},
},
)),
http.post(`${BACKEND_URL}/webapi/login`, () =>
http.post(`${BACKEND_URL}/webapi/login/`, () =>
HttpResponse.json({ message: 'success' })),
http.get(`${BACKEND_URL}/webapi/countries`, () =>
http.get(`${BACKEND_URL}/webapi/countries/`, () =>
HttpResponse.json({
message: 'it works!',
result: [{ code: 'CT', name: 'Country' }],
})),
http.get(`${BACKEND_URL}/webapi/countries`, () =>
http.get(`${BACKEND_URL}/webapi/countries/`, () =>
HttpResponse.json({ message: 'it works!!', result: [] })),
http.get(`${BACKEND_URL}/webapi/account`, () =>
http.get(`${BACKEND_URL}/webapi/account/`, () =>
HttpResponse.json(
{ message: 'fail', result: [] },
{
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils/api.nuxt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('api utilities', () => {

it('fetchWithCsrf: fetch countries runs correctly', async () => {
await expect(
fetchWithCsrf<ApiResponse<Country[]>>(`/webapi/countries`),
fetchWithCsrf<ApiResponse<Country[]>>(`/webapi/countries/`),
).resolves.toMatchObject(
expect.objectContaining({
result: [{ code: 'CT', name: 'Country' }],
Expand All @@ -30,7 +30,7 @@ describe('api utilities', () => {
it('fetchWithCsrf: fetch account info with 401 error', async () => {
mockNuxtImport('navigateTo', () => vi.fn());
await expect(
fetchWithCsrf<ApiResponse<Account>>(`/webapi/account`),
fetchWithCsrf<ApiResponse<Account>>(`/webapi/account/`),
).rejects.toThrowError(/401/);
expect(logout).toBeCalled();
expect(logout).toHaveBeenCalledOnce();
Expand Down
Loading