Skip to content

Conversation

provokateurin
Copy link
Contributor

@provokateurin provokateurin commented Apr 3, 2023

Closes #1798

@provokateurin provokateurin requested a review from a team as a code owner April 3, 2023 09:19
@provokateurin provokateurin requested a review from raleigh04 April 3, 2023 09:19
@netlify
Copy link

netlify bot commented Apr 3, 2023

Deploy Preview for stoplight-elements ready!

Name Link
🔨 Latest commit 5916c3d
🔍 Latest deploy log https://app.netlify.com/sites/stoplight-elements/deploys/64390496b6e27c0008645389
😎 Deploy Preview https://deploy-preview-2349--stoplight-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Apr 3, 2023

Deploy Preview for stoplight-elements-demo ready!

Name Link
🔨 Latest commit 5916c3d
🔍 Latest deploy log https://app.netlify.com/sites/stoplight-elements-demo/deploys/6439049665517700086f3d0a
😎 Deploy Preview https://deploy-preview-2349--stoplight-elements-demo.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@mnaumanali94
Copy link
Contributor

I think this should also close #2351

Copy link
Contributor

@dotslashderek dotslashderek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice and appreciated - yes @mnaumanali94 I do think this will fix the other issue as well - @provokateurin I think the test failures are pretty straightforward to fix, take a look at my comment and thanks for contributing!

@provokateurin provokateurin force-pushed the feature/content-type-accept-headers branch from 849fbb9 to de40cd3 Compare April 11, 2023 06:05
@provokateurin
Copy link
Contributor Author

@dotslashderek Tests don't seem to run?

@dotslashderek
Copy link
Contributor

@provokateurin yeah - we're trying to figure out what's going on with the CircleCI pipeline. I pushed a couple changes to trigger runs, then fixed the four TryIt failures. If you want to take a look at the HttpOperation test that's failing, I'd like to see what happens with the pipeline when you push a new commit. Otherwise no worries I'll take another look at this in the next day or two. Thanks again!

@provokateurin provokateurin force-pushed the feature/content-type-accept-headers branch from 17b5189 to 2bf99a5 Compare April 12, 2023 07:22
@provokateurin
Copy link
Contributor Author

@dotslashderek I dropped your changes because I made a mistake with the Accept header where it still added it with 0 accepted mime types. Afterwards your fixes for the tests were breaking it again, so I did it properly. Tests work locally now.

Copy link
Contributor

@dotslashderek dotslashderek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, but a second request - could you add a couple quick unit tests around getAcceptedMimeTypes (that's why I exported it in the suggestion) to build-request.spec.ts? - could be as simple as:

describe('getAcceptedMimeTypes', () => {
    const operationSingleResponse: IHttpOperation = {
      id: 'adsf',
      method: 'GET',
      path: '/a/path',
      responses: [
        {
          id: 'responseA',
          code: '200',
          contents: [
            {
              id: 'adsf',
              mediaType: 'application/json',
            },
            {
              id: 'dfvs',
              mediaType: 'application/json',
            },
            {
              id: 'aaaa',
              mediaType: 'multipart/form-data',
            },
          ],
        },
      ],
    };

    const operationMultipleResponses: IHttpOperation = {
      id: 'sfdf',
      method: 'POST',
      path: '/a/nother/path',
      responses: [
        {
          id: 'responseA',
          code: '200',
          contents: [
            {
              id: 'adsf',
              mediaType: 'application/json',
            },
            {
              id: 'dfvs',
              mediaType: 'application/json',
            },
          ],
        },
        {
          id: 'responseB',
          code: '200',
          contents: [
            {
              id: 'adsf',
              mediaType: 'application/json',
            },
            {
              id: 'dfvs',
              mediaType: 'multipart/form-data',
            },
          ],
        },
        {
          id: 'responseC',
          code: '200',
          contents: [
            {
              id: 'dfvs',
              mediaType: 'multipart/form-data',
            },
          ],
        },
        {
          id: 'responseB',
          code: '200',
          contents: [
            {
              id: 'adsf',
              mediaType: 'text/json',
            },
            {
              id: 'dfvs',
              mediaType: 'multipart/form-data',
            },
          ],
        },
      ],
    };

    it('Handles a single response with duplicates', () => {
      expect(getAcceptedMimeTypes(operationSingleResponse)).toStrictEqual(['application/json', 'multipart/form-data']);
    });

    it('Handles multiple responses and dedups appropriately', () => {
      expect(getAcceptedMimeTypes(operationMultipleResponses)).toStrictEqual([
        'application/json',
        'multipart/form-data',
        'text/json',
      ]);
    });
  });

Thanks! (And for fixing things properly w/ the TryIt tests 🙂 )

@provokateurin provokateurin force-pushed the feature/content-type-accept-headers branch from 2bf99a5 to 5916c3d Compare April 14, 2023 07:45
@provokateurin
Copy link
Contributor Author

@dotslashderek Added the tests

Copy link
Contributor

@dotslashderek dotslashderek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @provokateurin - thanks for taking care of this!

@provokateurin
Copy link
Contributor Author

Missing reviews or ready to merge?

@dotslashderek
Copy link
Contributor

Missing reviews or ready to merge?

Ready to merge!

@dotslashderek dotslashderek merged commit bbe782c into stoplightio:main Apr 17, 2023
@provokateurin
Copy link
Contributor Author

Thanks a lot!

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.

Elements does not include the Accept request header

3 participants