Skip to content
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

[Test] Enable unit test suite: api.test.ts #495

Merged
merged 1 commit into from
Jun 23, 2021

Conversation

ananzh
Copy link
Member

@ananzh ananzh commented Jun 18, 2021

Description

All the unit tests related to unused newsfeed are temporarily
skipped at forking. To build a clean unit test, we decide to
check and enable all the working unit tests. This PR checks
and enables api.test.ts.

Signed-off-by: Anan Zhuang [email protected]

Issues Resolved

#490

Test results

unit test for api.test.ts

yarn test:jest /home/anan/work/OpenSearch-Dashboards/src/plugins/newsfeed/public/lib/api.test.ts
yarn run v1.22.10
$ node scripts/jest /home/anan/work/OpenSearch-Dashboards/src/plugins/newsfeed/public/lib/api.test.ts
  console.error
    sorry, try again later!

      217 |       driver.fetchNewsfeedItems(http, config.service).pipe(
      218 |         catchError((err) => {
    > 219 |           window.console.error(err);
          |                          ^
      220 |           return Rx.of({
      221 |             error: err,
      222 |             opensearchDashboardsVersion,

      at CatchSubscriber.driver.fetchNewsfeedItems.pipe.err [as selector] (src/plugins/newsfeed/public/lib/api.ts:219:26)
      at CatchSubscriber.Object.<anonymous>.CatchSubscriber.error (node_modules/rxjs/src/internal/operators/catchError.ts:130:23)
      at node_modules/rxjs/src/internal/util/subscribeToPromise.ts:12:30

  console.error
    Sorry, try again later!

      217 |       driver.fetchNewsfeedItems(http, config.service).pipe(
      218 |         catchError((err) => {
    > 219 |           window.console.error(err);
          |                          ^
      220 |           return Rx.of({
      221 |             error: err,
      222 |             opensearchDashboardsVersion,

      at CatchSubscriber.driver.fetchNewsfeedItems.pipe.err [as selector] (src/plugins/newsfeed/public/lib/api.ts:219:26)
      at CatchSubscriber.Object.<anonymous>.CatchSubscriber.error (node_modules/rxjs/src/internal/operators/catchError.ts:130:23)
      at node_modules/rxjs/src/internal/util/subscribeToPromise.ts:12:30

  console.error
    Sorry, internal server error!

      217 |       driver.fetchNewsfeedItems(http, config.service).pipe(
      218 |         catchError((err) => {
    > 219 |           window.console.error(err);
          |                          ^
      220 |           return Rx.of({
      221 |             error: err,
      222 |             opensearchDashboardsVersion,

      at CatchSubscriber.driver.fetchNewsfeedItems.pipe.err [as selector] (src/plugins/newsfeed/public/lib/api.ts:219:26)
      at CatchSubscriber.Object.<anonymous>.CatchSubscriber.error (node_modules/rxjs/src/internal/operators/catchError.ts:130:23)
      at node_modules/rxjs/src/internal/util/subscribeToPromise.ts:12:30

  console.error
    Sorry, it's too cold to go outside!

      217 |       driver.fetchNewsfeedItems(http, config.service).pipe(
      218 |         catchError((err) => {
    > 219 |           window.console.error(err);
          |                          ^
      220 |           return Rx.of({
      221 |             error: err,
      222 |             opensearchDashboardsVersion,

      at CatchSubscriber.driver.fetchNewsfeedItems.pipe.err [as selector] (src/plugins/newsfeed/public/lib/api.ts:219:26)
      at CatchSubscriber.Object.<anonymous>.CatchSubscriber.error (node_modules/rxjs/src/internal/operators/catchError.ts:130:23)
      at node_modules/rxjs/src/internal/util/subscribeToPromise.ts:12:30

 PASS  src/plugins/newsfeed/public/lib/api.test.ts
  NewsfeedApiDriver
    ✓ Validates items for required fields (1 ms)
    shouldFetch
      ✓ defaults to true (4 ms)
      ✓ returns true if last fetch time precedes page load time (3 ms)
      ✓ returns false if last fetch time is recent enough (1 ms)
    updateHashes
      ✓ returns previous and current storage (3 ms)
      ✓ concatenates the previous hashes with the current (1 ms)
    modelItems
      ✓ Models empty set with defaults (1 ms)
      ✓ Selects default language (2 ms)
      ✓ Falls back to English when user language isn't present (1 ms)
      ✓ Models multiple items into an API FetchResult (1 ms)
      ✓ Filters expired (1 ms)
      ✓ Filters pre-published
  getApi
    ✓ creates a result (6 ms)
    ✓ hasNew is true when the service returns hashes not in the cache (26 ms)
    ✓ hasNew is false when service returns hashes that are all stored (3 ms)
    ✓ forwards an error (65 ms)
    Retry fetching
      ✓ retries until fetch doesn't error (50 ms)
      ✓ doesn't retry if fetch succeeds (3 ms)

Test Suites: 1 passed, 1 total
Tests:       18 passed, 18 total
Snapshots:   10 passed, 10 total
Time:        2.235 s

Overall test result:
Screen Shot 2021-06-18 at 10 14 24 AM

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

@ananzh ananzh added bug Something isn't working test:unit v1.0.0 labels Jun 18, 2021
@ananzh ananzh requested review from tmarkley, kavilla and boktorbb June 18, 2021 17:15
@ananzh ananzh self-assigned this Jun 18, 2021
@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 8d31722

@ananzh ananzh mentioned this pull request Jun 18, 2021
26 tasks
@ananzh ananzh changed the title Enable unit test suite: api.test.ts [Test] Enable unit test suite: api.test.ts Jun 18, 2021
@ananzh ananzh removed the bug Something isn't working label Jun 18, 2021
All the unit tests related to unused newsfeed are temporarily
skipped at forking. To build a clean unit test, we decide to
check and enable all the working unit tests. This PR checks
and enables api.test.ts.

Signed-off-by: Anan Zhuang <[email protected]>
@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed ed5c8c2

Copy link
Member

@kavilla kavilla left a comment

Choose a reason for hiding this comment

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

lgtm thanks

@ananzh ananzh merged commit d870129 into opensearch-project:main Jun 23, 2021
kavilla pushed a commit that referenced this pull request Jun 26, 2021
All the unit tests related to unused newsfeed are temporarily
skipped at forking. To build a clean unit test, we decide to
check and enable all the working unit tests. This PR checks
and enables api.test.ts.

Signed-off-by: Anan Zhuang <[email protected]>
kavilla pushed a commit that referenced this pull request Jun 26, 2021
All the unit tests related to unused newsfeed are temporarily
skipped at forking. To build a clean unit test, we decide to
check and enable all the working unit tests. This PR checks
and enables api.test.ts.

Signed-off-by: Anan Zhuang <[email protected]>
@ananzh ananzh deleted the i-490 branch September 14, 2021 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants