Skip to content

Generate ssdk request protocol tests #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented Mar 2, 2021

Description of changes:

This adds test generation for ssdk request deserialization. For example:

/**
 * Mixes constant and variable query string parameters
 */
it("RestJsonConstantAndVariableQueryStringMissingOneValue:ServerRequest", async () => {
  let testFunction = jest.fn();
  testFunction.mockReturnValue({});
  const testService: Partial<RestJsonService> = {
    ConstantAndVariableQueryString: testFunction as __Operation<
      ConstantAndVariableQueryStringCommandInput,
      ConstantAndVariableQueryStringCommandOutput
    >,
  };
  const handler = getRestJsonServiceHandler(testService as RestJsonService);
  const request = new HttpRequest({
    method: "GET",
    hostname: "foo.example.com",
    path: "/ConstantAndVariableQueryString",
    query: {
      foo: "bar",
      baz: "bam",
    },
    headers: {},
    body: Readable.from([""]),
  });
  await handler.handle(request);

  expect(testFunction.mock.calls.length).toBe(1);
  let r: any = testFunction.mock.calls[0][0];

  const paramsToValidate: any = [
    {
      baz: "bam",
    },
  ][0];
  Object.keys(paramsToValidate).forEach((param) => {
    expect(r[param]).toBeDefined();
    expect(equivalentContents(r[param], paramsToValidate[param])).toBe(true);
  });
});

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@JordonPhillips JordonPhillips force-pushed the server-serde-protocol-tests branch from 7896c78 to 523cf7e Compare March 3, 2021 15:58
@JordonPhillips JordonPhillips merged commit 4bf58c3 into smithy-lang:ssdk Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants