1.1.2Updated a month ago
import { assertEquals } from "@std/assert";
import { Testbed } from "../../testbed.ts";

import { Fail } from "../../../modules/responses/fail.ts";
import { Succeed } from "../../../modules/responses/succeed.ts";

Testbed('Response generation', ({ Test }) => {

  Test('Succeed() works without a body and sets status to 200', () => {
    const response = Succeed();
    assertEquals(response.status, 200);
  })

  Test('Succeed() works with a body and sets status to 200', () => {
    const response = Succeed('Custom message');
    assertEquals(response.status, 200);
  })

  Test('Succeed() correctly sets the body and sets status to 200', async () => {
    const test_text = 'Custom message';

    const response = Succeed(test_text);

    assertEquals(await response.text(), test_text);
  })

  Test('Fail() works without a body and sets status to 404', () => {
    const response = Fail();
    assertEquals(response.status, 404);
  })

  Test('Fail() works with a body and sets status to 404', () => {
    const response = Fail('Custom message');
    assertEquals(response.status, 404);
  })

  Test('Fail() correctly sets the body and sets status to 404', async () => {
    const test_text = 'Custom message';

    const response = Fail(test_text);

    assertEquals(await response.text(), test_text);
  })

})