Skip to content

Commit

Permalink
Merge branch 'master' into recurring-tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Sep 27, 2022
2 parents 1609868 + 69c6ca5 commit d0f1943
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/lib/api/addTask.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import apiFetch from './fetch2';
import fetch2 from './fetch2';

// Requires that user be authenticated.
export async function addTask(
Expand All @@ -7,7 +7,7 @@ export async function addTask(
cents: number,
recurrence?: Record<string, number>
): Promise<Response> {
const response = await apiFetch('me/tasks', true, 'POST', {
const response = await fetch2('me/tasks', true, 'POST', {
task,
due,
cents,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/editTask.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

// Requires that user be authenticated.
export async function editTask(
id: string,
due: string,
cents: number
): Promise<Response> {
const response = await apiFetch(`me/tasks/${id}`, true, 'PUT', {
const response = await fetch1(`me/tasks/${id}`, true, 'PUT', {
due,
cents,
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib/api/fetch1.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';
import { expect, it, describe, vi } from 'vitest';

vi.mock('./fetch1', () => {
return vi.importActual('./fetch1');
});

describe('apiFetch', () => {
describe('fetch1', () => {
it('uses localStorage token', async () => {
fetchMock.mockResponse(JSON.stringify({}));

Expand All @@ -14,7 +14,7 @@ describe('apiFetch', () => {
global.localStorage.setItem('token', token);

const url = 'https://example.com';
await apiFetch(url);
await fetch1(url);

expect(fetch).toHaveBeenCalledWith(
expect.anything(),
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/getCheckoutSession.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

export async function getCheckoutSession(): Promise<CheckoutSession> {
const response = await apiFetch('payments/checkout/session');
const response = await fetch1('payments/checkout/session');

return response.json() as Promise<CheckoutSession>;
}
4 changes: 2 additions & 2 deletions src/lib/api/getMe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

export async function getMe(): Promise<User> {
const response = await apiFetch('me', true);
const response = await fetch1('me', true);

if (!response.ok) {
throw new Error('Failed to get me');
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/getTasks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

export async function getTasks(): Promise<unknown> {
const response = await apiFetch('me/tasks', true);
const response = await fetch1('me/tasks', true);

return response.json();
}
4 changes: 2 additions & 2 deletions src/lib/api/getTimezones.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

export async function getTimezones(): Promise<string[]> {
const response = await apiFetch('timezones');
const response = await fetch1('timezones');

return response.json() as Promise<string[]>;
}
4 changes: 2 additions & 2 deletions src/lib/api/register.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

export default function register(
name: string,
Expand All @@ -7,7 +7,7 @@ export default function register(
timezone: string,
checkoutSessionId: string | null
): Promise<Response> {
return apiFetch('account/register', false, 'POST', {
return fetch1('account/register', false, 'POST', {
name: name,
email: email,
password: password,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/updatePassword.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

export function updatePassword(
oldPassword: string,
newPassword: string
): Promise<Response> {
return apiFetch('me', true, 'PUT', {
return fetch1('me', true, 'PUT', {
old_password: oldPassword,
new_password: newPassword,
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/updateTask.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import apiFetch from './fetch1';
import fetch1 from './fetch1';

export interface TaskInput {
complete?: boolean;
Expand All @@ -7,5 +7,5 @@ export interface TaskInput {

// Requires that user be authenticated.
export function updateTask(taskId: string, data: TaskInput): Promise<Response> {
return apiFetch('me/tasks/' + taskId, true, 'PUT', data);
return fetch1('me/tasks/' + taskId, true, 'PUT', data);
}
4 changes: 2 additions & 2 deletions src/lib/api/useGetApiToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMutation } from 'react-query';
import apiFetch from './fetch1';
import fetch1 from './fetch1';
import { UseMutationResult } from 'react-query';

export function useGetApiToken(): UseMutationResult<
Expand All @@ -9,7 +9,7 @@ export function useGetApiToken(): UseMutationResult<
unknown
> {
return useMutation<string>('api-token', async () => {
const response = await apiFetch('me/token', true, 'GET');
const response = await fetch1('me/token', true, 'GET');
return response.text();
});
}

1 comment on commit d0f1943

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.