Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Use a non-versioned API URL to mock analytics requests, too #1045

Merged
merged 2 commits into from
Mar 9, 2022

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Mar 3, 2022

Fixes

Fixes #915 by @obulat

Description

This PR creates two ApiService objects: one is versioned, for most endpoints, and an unversioned one for the analytics endpoints.
Some data services were also refactored to reuse code from other services (getMediaSlug, for example), and the bug-report was removed as it is unused.
The proxy port was also changed from 3000 to 3322 because when I was testing, the API was running in Docker, and 3000 port was busy.
It also renames the update-tapes to recreate-tapes, and adds an update-tapes script that does not completely delete all the tapes, but simply adds any tapes that are missing. This way, we can update a single tape when any e2e test changes, and don't have too many changes in a PR.

Testing Instructions

Enable internal analytics:

enableInternalAnalytics: process.env.ENABLE_INTERNAL_ANALYTICS ?? 'false',

Run pnpm run update-tapes. This will delete all the tapes files, and, more importantly, it will save any response that isn't found in test/tapes directory. You should see a lot of tapes for analytics responses. They are all 404, but they are there.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@obulat obulat added 🟩 priority: low Low priority and doesn't need to be rushed 🌟 goal: addition Addition of new feature 💻 aspect: code Concerns the software code in the repository labels Mar 3, 2022
@obulat obulat requested a review from a team as a code owner March 3, 2022 13:49
@obulat obulat self-assigned this Mar 3, 2022
@obulat obulat requested review from krysal and dhruvkb March 3, 2022 13:49
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

Is there any way to run talkback with the normal pnpm test:e2e script? Or is it only possible with the CI version?

Looking good so far, just testing locally but will probably be able to approve soon.

src/data/api-service.js Outdated Show resolved Hide resolved
test/proxy.js Outdated
Comment on lines 20 to 22
const recordMode = updatingTapes
? talkback.Options.RecordMode.NEW
: talkback.Options.RecordMode.DISABLED
: talkback.Options.RecordMode.NEW
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this make recordMode always NEW? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also left-over from last-minute debugging :(

test/proxy.js Outdated
port: 3000,
port: 3322,
Copy link
Contributor

Choose a reason for hiding this comment

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

😅 This seems like a better choice considering how many other things live on port 3000 by default anyway (I know a few that are missing from this list too, like Flask I think?)

https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

In fact, I kind of wonder if we shouldn't switch all of our stuff to use ports in the completely unregistered "temporary services" range of 49152–65535.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

49152 it is, then :)

Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

This LGTM. I noticed that in addition to #985 talkback also didn't stop running when I ran pnpm ci:e2e-test locally even though the tests passed and didn't crash or anything 😕 Did you notice that happening as well?

@sarayourfriend
Copy link
Contributor

Oh I just noticed another tape was created when I ran pnpm ci:e2e-test locally.

@obulat
Copy link
Contributor Author

obulat commented Mar 4, 2022

Oh I just noticed another tape was created when I ran pnpm ci:e2e-test locally.

I just spent 15 minutes chasing these new tapes. There is often 1 image or audio request that's new. I think it's one of the related images or audio that sometimes change. I guess we should open an issue to mock related image / audio requests...

@sarayourfriend
Copy link
Contributor

I just spent 15 minutes chasing these new tapes. There is often 1 image or audio request that's new. I think it's one of the related images or audio that sometimes change. I guess we should open an issue to mock related image / audio requests...

I think the fix I have in the proxy to replace API results that reference the upstream server with proxy references will address this, so I wouldn't sweat it.

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

Works well, LGTM 👍

@obulat obulat merged commit feeabd3 into main Mar 9, 2022
@obulat obulat deleted the mock_analytics_requests_with_talkback branch March 9, 2022 12:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🌟 goal: addition Addition of new feature 🟩 priority: low Low priority and doesn't need to be rushed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mock e2e testing analytics network requests
3 participants