vorteil/direktiv

View on GitHub
ui/src/api/__tests__/apiFactory.test.ts

Summary

Maintainability
F
4 days
Test Coverage

File apiFactory.test.ts has 414 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import "cross-fetch/polyfill";

import { ResponseParser, apiFactory } from "../apiFactory";
import {
  afterAll,
Severity: Minor
Found in ui/src/api/__tests__/apiFactory.test.ts - About 5 hrs to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        await waitFor(() => {
          expect(result.current.isSuccess).toBe(false);
          expect(result.current.status).toBe("error");
          const res = result.current.error;
          const parsedRes = ApiErrorSchema.safeParse(res);
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 1 other location - About 6 hrs to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 213..225

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 162.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        await waitFor(() => {
          expect(result.current.isSuccess).toBe(false);
          expect(result.current.status).toBe("error");
    
          const res = result.current.error;
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 1 other location - About 6 hrs to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 307..318

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 162.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      rest.get(apiEndpoint, (req, res, ctx) =>
        req?.headers?.get("direktiv-token") === API_KEY
          ? res(
              ctx.json({
                response: "this works",
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 1 other location - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 43..51

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 68.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

      rest.get(apiEndpointWithDynamicSegment, (req, res, ctx) =>
        req?.headers?.get("direktiv-token") === API_KEY
          ? res(
              ctx.json({
                response: "dynamic segment this works",
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 1 other location - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 34..42

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 68.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        await waitFor(() => {
          expect(result.current.isSuccess).toBe(true);
          expect(result.current.data?.response).toBe("this works");
        });
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 2 other locations - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 369..372
    ui/src/api/__tests__/apiFactory.test.ts on lines 432..435

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 64.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        await waitFor(() => {
          expect(result.current.isSuccess).toBe(true);
          expect(result.current.data?.my).toBe("custom header");
        });
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 2 other locations - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 192..195
    ui/src/api/__tests__/apiFactory.test.ts on lines 369..372

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 64.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        await waitFor(() => {
          expect(result.current.isSuccess).toBe(true);
          expect(result.current.data?.response).toBe("dynamic segment this works");
        });
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 2 other locations - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 192..195
    ui/src/api/__tests__/apiFactory.test.ts on lines 432..435

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 64.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        const { result } = renderHook(
          () =>
            useQuery({
              queryKey: ["getmyapikey", API_KEY],
              queryFn: () =>
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 2 other locations - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 293..306
    ui/src/api/__tests__/apiFactory.test.ts on lines 322..335

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 63.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        const { result } = renderHook(
          () =>
            useQuery({
              queryKey: ["getmyapikey", API_KEY],
              queryFn: () =>
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 2 other locations - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 269..282
    ui/src/api/__tests__/apiFactory.test.ts on lines 293..306

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 63.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

        const { result } = renderHook(
          () =>
            useQuery({
              queryKey: ["getmyapikey", API_KEY],
              queryFn: () =>
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 2 other locations - About 1 hr to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 269..282
    ui/src/api/__tests__/apiFactory.test.ts on lines 322..335

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 63.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const apiPost = apiFactory({
      url: () => apiEndpointPost,
      method: "POST",
      schema: z.object({
        body: z.string(),
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 4 other locations - About 50 mins to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 100..106
    ui/src/api/__tests__/apiFactory.test.ts on lines 122..126
    ui/src/api/__tests__/apiFactory.test.ts on lines 128..134
    ui/src/api/__tests__/apiFactory.test.ts on lines 136..142

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const api404 = apiFactory({
      url: () => apiEndpoint404,
      method: "GET",
      schema: z.object({
        response: z.string(),
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 4 other locations - About 50 mins to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 100..106
    ui/src/api/__tests__/apiFactory.test.ts on lines 122..126
    ui/src/api/__tests__/apiFactory.test.ts on lines 136..142
    ui/src/api/__tests__/apiFactory.test.ts on lines 144..150

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const apiJSONError = apiFactory({
      url: () => apiEndpointJSONError,
      method: "GET",
      schema: z.object({
        response: z.string(),
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 4 other locations - About 50 mins to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 100..106
    ui/src/api/__tests__/apiFactory.test.ts on lines 122..126
    ui/src/api/__tests__/apiFactory.test.ts on lines 128..134
    ui/src/api/__tests__/apiFactory.test.ts on lines 144..150

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const getMyApi = apiFactory({
      url: () => apiEndpoint,
      method: "GET",
      schema: z.object({
        response: z.string(),
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 4 other locations - About 50 mins to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 122..126
    ui/src/api/__tests__/apiFactory.test.ts on lines 128..134
    ui/src/api/__tests__/apiFactory.test.ts on lines 136..142
    ui/src/api/__tests__/apiFactory.test.ts on lines 144..150

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 5 locations. Consider refactoring.
    Open

    const textResponse = apiFactory({
      url: () => apiEndpointTextResponse,
      method: "GET",
      schema: z.object({ body: z.string() }),
    });
    Severity: Major
    Found in ui/src/api/__tests__/apiFactory.test.ts and 4 other locations - About 50 mins to fix
    ui/src/api/__tests__/apiFactory.test.ts on lines 100..106
    ui/src/api/__tests__/apiFactory.test.ts on lines 128..134
    ui/src/api/__tests__/apiFactory.test.ts on lines 136..142
    ui/src/api/__tests__/apiFactory.test.ts on lines 144..150

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status