Skip to content

running all test causes a "connection lost" #1007

@ekeren

Description

@ekeren

When trying to run all test for this code (playground link)

I get the following:
image

When running one by one it works ok.

Here is the code:

bring cloud;
bring util;
bring expect;
bring http;

struct BookRequest {
  title: str;
  author: str;
}
struct BookResposne extends BookRequest { 
  bookID: str;
  createdAt: str;
}

let api = new cloud.Api();

api.post("/books", inflight (req: cloud.ApiRequest) => {
  try {
    let bookRequest = BookRequest.parseJson(req.body!);
    let response = BookResposne {
          bookID: util.uuidv4(),
          title: bookRequest.title,
         author: bookRequest.author,
         createdAt: "2024-04-14"
    };
    return {
      status: 200, 
      body: Json.stringify(response)
   };
  } catch e {
    return {
      status: 400,
      body: e
    };
  }
});
  


test "POST /books should return 200 with correct body " {
  let body = Json.stringify({title: "A Title", author: "An Author"});

  let result = http.post("{api.url}/books", { body: body });

  expect.equal(result.status, 200);
}

test "POST /books should return 400 without body " {

  let result = http.post("{api.url}/books");

  expect.equal(result.status, 400);
}

test "POST /books should return 400 with empty body " {
  let body = Json.stringify({});

  let result = http.post("{api.url}/books", { body: body });

  expect.equal(result.status, 400);
}

test "POST /books should return 400 without title " {
  let body = Json.stringify({ author: "An Author"});

  let result = http.post("{api.url}/books", { body: body });

  expect.equal(result.status, 400);
}

test "POST /books should return 400 without author " {
  let body = Json.stringify({title: "A Title" });

  let result = http.post("{api.url}/books", { body: body });

  expect.equal(result.status, 400);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions