Skip to content

Commit

Permalink
move tests to __tests__ (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenkilbourn authored Jan 7, 2025
1 parent 1d68262 commit 4905d3c
Show file tree
Hide file tree
Showing 30 changed files with 44 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, expect, it, vi } from 'vitest';
import { POST, PUT } from '@/app/api/create-ingest/route';
import UpdatePR from '@/utils/UpdatePR';
import { NextRequest } from 'next/server';
import CreatePR from '@/utils/CreatePR';
import UpdatePR from '@/utils/githubUtils/UpdatePR';
import CreatePR from '@/utils/githubUtils/CreatePR';

vi.mock('@/utils/UpdatePR');
vi.mock('@/utils/CreatePR');
vi.mock('@/utils/githubUtils/UpdatePR');
vi.mock('@/utils/githubUtils/CreatePR');

describe('POST /create-ingest', () => {
it('returns GitHub URL on successful PR creation', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it, vi } from 'vitest';
import { GET } from '@/app/api/list-ingests/route';
import ListPRs from '@/utils/ListPRs';
import ListPRs from '@/utils/githubUtils/ListPRs';
import { NextRequest } from 'next/server';
import { Endpoints } from '@octokit/types';

Expand All @@ -12,7 +12,7 @@ type SimplifiedPullRequest = Pick<PullRequest, 'id' | 'title'> & {
};

// Mock implementation
vi.mock('@/utils/ListPRs', () => {
vi.mock('@/utils/githubUtils/ListPRs', () => {
const mockPRs: SimplifiedPullRequest[] = [
{
id: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { GET } from '@/app/api/retrieve-ingest/route';
import RetrieveJSON from '@/utils/RetrieveJSON';
import RetrieveJSON from '@/utils/githubUtils/RetrieveJSON';
import { NextRequest } from 'next/server';

// Mock implementation
vi.mock('@/utils/RetrieveJSON', () => {
vi.mock('@/utils/githubUtils/RetrieveJSON', () => {
return {
default: vi.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { cleanup, render, screen } from '@testing-library/react';
import { describe, it, expect, vi, afterEach } from 'vitest';
import ErrorModal from './ErrorModal';
import ErrorModal from '@/components/ErrorModal';

// Mock StyledModal
vi.mock('@/components/StyledModal', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
import { describe, it, vi, expect, afterEach } from 'vitest';
import SuccessModal from './SuccessModal';
import SuccessModal from '@/components/SuccessModal';


// Mock StyledModal
vi.mock('./StyledModal', () => ({
vi.mock('@/components/StyledModal', () => ({
__esModule: true,
default: vi.fn(({ children, okText, onOk }) => (
<div data-testid="styled-modal">
Expand Down
2 changes: 1 addition & 1 deletion middleware.test.ts → __tests__/middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, vi } from 'vitest';
import { NextRequest } from 'next/server';
import { middleware } from './middleware';
import { middleware } from '@/middleware';
import { runWithAmplifyServerContext } from '@/utils/amplify-server-util';
import { fetchAuthSession } from 'aws-amplify/auth/server';

Expand Down
2 changes: 1 addition & 1 deletion app/page.test.tsx → __tests__/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { describe, it, expect, beforeAll } from 'vitest';
import Home from './page';
import Home from '@/app/page';
import { Amplify } from 'aws-amplify';
import { config } from '@/utils/aws-exports';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { describe, it, expect, beforeAll } from 'vitest';
import CreateIngest from './page';
import CreateIngest from '@/app/create-ingest/page';
import { Amplify } from 'aws-amplify';
import { config } from '@/utils/aws-exports';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { setupServer } from 'msw/node';
import { handlers } from '@/__mocks__/handlers';
import { http, HttpResponse } from 'msw';

import EditIngest from './page';
import EditIngest from '@/app/edit-ingest/page';

global.window.getComputedStyle = vi.fn().mockImplementation(() => ({
getPropertyValue: vi.fn(),
Expand Down Expand Up @@ -79,6 +79,6 @@ describe('Edit Ingest Page', () => {
const modalTitle = screen.getByText(/Collection Updated/i);
expect(modalTitle).toBeInTheDocument();
});
});
}, 10000);

});
12 changes: 6 additions & 6 deletions utils/CreatePR.test.ts → __tests__/utils/CreatePR.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, it, expect, vi, beforeEach, beforeAll, afterAll, Mock } from 'vitest';
import CreatePR from './CreatePR';
import { createOctokit } from './OctokitFactory';
import GetGithubToken from './GetGithubToken';
import CreatePR from '@/utils/githubUtils/CreatePR';
import { createOctokit } from '@/utils/githubUtils/OctokitFactory';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';
import { RequestError } from '@octokit/request-error';

vi.mock('./OctokitFactory');
vi.mock('./GetGithubToken');
vi.mock('./FormatFilename', () => ({
vi.mock('@/utils/githubUtils/OctokitFactory');
vi.mock('@/utils/githubUtils/GetGithubToken');
vi.mock('@/utils/FormatFilename', () => ({
formatFilename: (name: string) => name.replace(/\s+/g, '-').toLowerCase(),
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { formatFilename } from './FormatFilename';
import { formatFilename } from '@/utils/FormatFilename';

describe('formatFilename', () => {
it('removes non-alphanumeric characters except dash and underscore', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
import GetGithubToken from './GetGithubToken';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';
import { Octokit } from '@octokit/rest';

vi.mock('@octokit/rest', () => ({
Expand Down
6 changes: 3 additions & 3 deletions utils/ListPRs.test.ts → __tests__/utils/ListPRs.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, it, expect, vi } from 'vitest';
import { Octokit } from '@octokit/rest';
import ListPRs from './ListPRs';
import GetGithubToken from './GetGithubToken';
import ListPRs from '@/utils/githubUtils/ListPRs';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';

vi.mock('./GetGithubToken', () => ({
vi.mock('@/utils/githubUtils/GetGithubToken', () => ({
default: vi.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
import RetrieveJSON from './RetrieveJSON';
import GetGithubToken from './GetGithubToken';
import RetrieveJSON from '@/utils/githubUtils/RetrieveJSON';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';
import { Octokit } from '@octokit/rest';

vi.mock('@octokit/rest', () => ({
Octokit: vi.fn(),
}));

vi.mock('./GetGithubToken');
vi.mock('@/utils/githubUtils/GetGithubToken');

describe('RetrieveJSON', () => {
const mockGetContent = vi.fn();
Expand Down
6 changes: 3 additions & 3 deletions utils/UpdatePR.test.ts → __tests__/utils/UpdatePR.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
import UpdatePR from './UpdatePR';
import GetGithubToken from './GetGithubToken';
import UpdatePR from '@/utils/githubUtils/UpdatePR';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';
import { Octokit } from '@octokit/rest';

vi.mock('@octokit/rest', () => ({
Octokit: vi.fn(),
}));

vi.mock('./GetGithubToken');
vi.mock('@/utils/githubUtils/GetGithubToken');

describe('UpdatePR', () => {
const mockCreateOrUpdateFileContents = vi.fn();
Expand Down
4 changes: 2 additions & 2 deletions app/api/create-ingest/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CreatePR from '@/utils/CreatePR';
import UpdatePR from '@/utils/UpdatePR';
import CreatePR from '@/utils/githubUtils/CreatePR';
import UpdatePR from '@/utils/githubUtils/UpdatePR';
import { NextRequest, NextResponse } from 'next/server';

export async function POST(request: NextRequest) {
Expand Down
2 changes: 1 addition & 1 deletion app/api/list-ingests/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ListPRs from '@/utils/ListPRs';
import ListPRs from '@/utils/githubUtils/ListPRs';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
Expand Down
2 changes: 1 addition & 1 deletion app/api/retrieve-ingest/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import RetrieveJSON from '@/utils/RetrieveJSON';
import RetrieveJSON from '@/utils/githubUtils/RetrieveJSON';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
Expand Down
2 changes: 1 addition & 1 deletion components/IngestCreationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useState } from 'react';

import { Status } from '@/types/global';
import IngestForm from './IngestForm';
import IngestForm from '@/components/IngestForm';
import uiSchema from '@/FormSchemas/uischema.json';

function IngestCreationForm({
Expand Down
2 changes: 1 addition & 1 deletion components/IngestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Theme as AntDTheme } from '@rjsf/antd';
import validator from '@rjsf/validator-ajv8';
import { JSONSchema7 } from 'json-schema';

import ObjectFieldTemplate from '../ObjectFieldTemplate';
import ObjectFieldTemplate from '@/utils/ObjectFieldTemplate';
import jsonSchema from '@/FormSchemas/jsonschema.json';
import { RJSFSchema, UiSchema } from '@rjsf/utils';

Expand Down
2 changes: 1 addition & 1 deletion components/SuccessModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import StyledModal from './StyledModal';
import StyledModal from '@/components/StyledModal';
import { Status } from '@/types/global';

type SuccessModalProps =
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"**/*.tsx",
".next/types/**/*.ts",
"./types/global.d.ts",
"./jest-setup.ts"
],
"exclude": ["node_modules"]
}
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/CreatePR.ts → utils/githubUtils/CreatePR.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createOctokit } from './OctokitFactory';
import { RequestError } from '@octokit/request-error';
import { formatFilename } from './FormatFilename';
import { formatFilename } from '@/utils/FormatFilename';
import GetGithubToken from './GetGithubToken';

interface Data {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/ListPRs.ts → utils/githubUtils/ListPRs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from '@octokit/rest';
import { Endpoints } from '@octokit/types';
import GetGithubToken from './GetGithubToken';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';

const base = process.env.TARGET_BRANCH ||'main';
const prefix = 'Ingest Request for ';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Octokit } from '@octokit/rest';
import GetGithubToken from './GetGithubToken';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';

const targetPath = 'ingestion-data/staging/dataset-config';

Expand Down
2 changes: 1 addition & 1 deletion utils/UpdatePR.ts → utils/githubUtils/UpdatePR.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Octokit } from '@octokit/rest';
import GetGithubToken from './GetGithubToken';
import GetGithubToken from '@/utils/githubUtils/GetGithubToken';

const UpdatePR = async (
ref: string,
Expand Down

0 comments on commit 4905d3c

Please sign in to comment.