stablekernel/aqueduct

Question... How do I write a test for a request with a body?

Prn-Ice opened this issue · 7 comments

I want to write a test for one of my resource requests, but I don't know how to add the body params.

I currently have.

test(
      'GET /create should return 200 when called with valid params',
      () async {
        expectResponse(
          await harness.agent.get(
            "/create",
            query: {
              'name': 'Prince',
              'email': 'p@g',
              'phone': '080',
            },
          ),
          200,
          body: {
            'name': 'Prince',
            'email': 'p@g',
            'phone': '080',
          },
        );
      },
    )

Maybe, you don't need to open a Issue, in http://slackaqueductsignup.herokuapp.com/, there are many people that can you help

Thanks, will do

nice, please close this Issue 🙏🏼

@Prn-Ice
Do you found your solution?

If not, here's an example of one of my tests:
dart expect( await agent.post(PATH, body: jsonEncode( { ... your data to send ...}, ), headers: <String, dynamic>{}, ), hasBody(jsonEncode(<String, dynamic>{ ... your expected body ... })));

Sorry @jairoFernandez for taking go long.

@jayjah I didn't. I'm trying to verify a 200 response when I receive a correct request with a body.

@Prn-Ice
Ah I see, does the following help you?

// response code
    expectResponse(response, 200);
// length of response body
    expect(response, hasBody(greaterThan(0)));
// expect specific body responses
    expect(response, hasBody(partial({'id': 1, 'image': isNotNull})));