-
Notifications
You must be signed in to change notification settings - Fork 116
test: scaffold unit tests in composables and api client package #419
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
Frodigo
merged 11 commits into
develop
from
test/m2-14-scaffold-unit-tests-in-composables-and-api-client-package
Jan 17, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ffcca90
test(composables): added jest config
KevinGorjan 2648014
tests(composables): rewritten test + fix in productGetter
KevinGorjan 560a82e
tests(composables): updated configuration in jest.config.js
KevinGorjan 9d27c88
tests(api-client): added tests for api-client + move general config t…
KevinGorjan 18f20f2
tests(api-client): added jest configuration + simple test
KevinGorjan 8d65662
chore: removed jest-environment-jsdom-sixteen
f60013f
tests(theme): reverted back and removed jest.base.config.json
KevinGorjan 3243f7b
test(composables): reverted back and removed jest.base.config.json
KevinGorjan 8f3986b
test(api-client): reverted back and removed jest.base.config.json
KevinGorjan 8dc12fe
chore: removed jest.base.config.json
KevinGorjan 5f05199
chore: merge develop into current branch
KevinGorjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/api-client/__tests__/api/storeConfig/storeConfig.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import request from '../../setup/request'; | ||
| import {STORE_CONFIG_MOCK_RESP} from './../../mockData/api/storeConfig' | ||
|
|
||
| describe('[Magento-API-Client] storeConfig', () => { | ||
| it('Fetching the storeConfig', async () => { | ||
| const res = await request({ | ||
| body: JSON.stringify({ | ||
| query: ` | ||
| query { | ||
| storeConfig { | ||
| allow_guests_to_write_product_reviews | ||
| allow_items | ||
| allow_order | ||
| base_currency_code | ||
| catalog_default_sort_by | ||
| category_fixed_product_tax_display_setting | ||
| cms_home_page | ||
| cms_no_cookies | ||
| cms_no_route | ||
| configurable_thumbnail_source | ||
| copyright | ||
| default_description | ||
| default_display_currency_code | ||
| default_keywords | ||
| default_title | ||
| grid_per_page | ||
| grid_per_page_values | ||
| head_shortcut_icon | ||
| header_logo_src | ||
| is_default_store | ||
| is_default_store_group | ||
| list_mode | ||
| list_per_page | ||
| list_per_page_values | ||
| locale | ||
| logo_alt | ||
| logo_height | ||
| logo_width | ||
| magento_wishlist_general_is_enabled | ||
| minimum_password_length | ||
| no_route | ||
| product_fixed_product_tax_display_setting | ||
| product_reviews_enabled | ||
| required_character_classes_number | ||
| root_category_uid | ||
| sales_fixed_product_tax_display_setting | ||
| store_code | ||
| store_group_code | ||
| store_group_name | ||
| store_name | ||
| store_sort_order | ||
| timezone | ||
| title_prefix | ||
| title_separator | ||
| title_suffix | ||
| use_store_in_url | ||
| website_code | ||
| website_name | ||
| weight_unit | ||
| welcome | ||
| } | ||
| } | ||
| ` | ||
| }) | ||
| }); | ||
| const { data } = await res.json(); | ||
|
|
||
| expect(data).toEqual(STORE_CONFIG_MOCK_RESP); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| const STORE_CONFIG_MOCK_RESP = { | ||
| storeConfig: { | ||
| allow_guests_to_write_product_reviews: '1', | ||
| allow_items: null, | ||
| allow_order: null, | ||
| base_currency_code: 'USD', | ||
| catalog_default_sort_by: 'position', | ||
| category_fixed_product_tax_display_setting: 'FPT_DISABLED', | ||
| cms_home_page: 'home', | ||
| cms_no_cookies: 'enable-cookies', | ||
| cms_no_route: 'no-route', | ||
| configurable_thumbnail_source: 'parent', | ||
| copyright: 'Copyright © 2013-present Magento, Inc. All rights reserved.', | ||
| default_description: null, | ||
| default_display_currency_code: 'USD', | ||
| default_keywords: null, | ||
| default_title: 'Magento Commerce', | ||
| grid_per_page: 12, | ||
| grid_per_page_values: '12,24,36', | ||
| head_shortcut_icon: null, | ||
| header_logo_src: null, | ||
| is_default_store: true, | ||
| is_default_store_group: true, | ||
| list_mode: 'grid-list', | ||
| list_per_page: 10, | ||
| list_per_page_values: '5,10,15,20,25', | ||
| locale: 'en_US', | ||
| logo_alt: null, | ||
| logo_height: null, | ||
| logo_width: null, | ||
| magento_wishlist_general_is_enabled: '1', | ||
| minimum_password_length: '8', | ||
| no_route: 'cms/noroute/index', | ||
| product_fixed_product_tax_display_setting: 'FPT_DISABLED', | ||
| product_reviews_enabled: '1', | ||
| required_character_classes_number: '3', | ||
| root_category_uid: 'Mg==', | ||
| sales_fixed_product_tax_display_setting: 'FPT_DISABLED', | ||
| store_code: 'default', | ||
| store_group_code: 'main_website_store', | ||
| store_group_name: 'Main Website Store', | ||
| store_name: 'Default Store View', | ||
| store_sort_order: 0, | ||
| timezone: 'America/Chicago', | ||
| title_prefix: null, | ||
| title_separator: '-', | ||
| title_suffix: null, | ||
| use_store_in_url: false, | ||
| website_code: 'base', | ||
| website_name: 'Main Website', | ||
| weight_unit: 'lbs', | ||
| welcome: 'Default welcome msg!', | ||
| }, | ||
| }; | ||
|
|
||
| export { | ||
| STORE_CONFIG_MOCK_RESP, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { graphql } from 'msw'; | ||
| import {STORE_CONFIG_MOCK_RESP} from './../mockData/api/storeConfig' | ||
|
|
||
| const magento = graphql.link('https://magento2-instance.vuestorefront.io/graphql'); | ||
|
|
||
| export const handlers = [ | ||
| magento.query('storeConfig', (req, res, ctx) => res( | ||
| ctx.data({ | ||
| data: STORE_CONFIG_MOCK_RESP, | ||
| }), | ||
| )), | ||
| ]; |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import fetch from 'cross-fetch'; | ||
|
|
||
| const request = ({ body }) => fetch('https://magento2-instance.vuestorefront.io/graphql', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body, | ||
| }); | ||
|
|
||
| export default request; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { setupServer } from 'msw/node'; | ||
| import { handlers } from './handlers'; | ||
|
|
||
| export const server = setupServer(...handlers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,71 @@ | ||
| const baseConfig = require('../../jest.base.config'); | ||
|
|
||
| /* eslint-disable unicorn/prefer-module */ | ||
| module.exports = { | ||
| ...baseConfig, | ||
| transform: { | ||
| ...baseConfig.transform, | ||
| '\\.(gql|graphql)$': 'jest-transform-graphql', | ||
| globals: { | ||
| __DEV__: true, | ||
| }, | ||
| coverageReporters: [ | ||
| 'lcov', | ||
| ], | ||
| coverageThreshold: { | ||
| global: {}, | ||
| }, | ||
| setupFilesAfterEnv: ['./__tests__/setup.ts'], | ||
| coveragePathIgnorePatterns: [ | ||
| '/node_modules/', | ||
| '.d.ts$', | ||
| '/__mocks__/', | ||
| ], | ||
| coverageDirectory: './coverage/', | ||
| moduleNameMapper: { | ||
| '^@/(.*)$': '<rootDir>/$1', | ||
| '^~/(.*)$': '<rootDir>/$1', | ||
| 'api-client(.*)$': '<rootDir>$1', | ||
| }, | ||
| testEnvironment: 'jsdom', | ||
| transform: { | ||
| '^.+\\.(ts)$': 'ts-jest', | ||
| '^.+\\.js$': 'babel-jest', | ||
| }, | ||
| transformIgnorePatterns: [ | ||
| 'node_modules', | ||
| '<rootDir>/node_modules', | ||
| ], | ||
| testMatch: [ | ||
| '<rootDir>/**/__tests__/**/*spec.[jt]s?(x)', | ||
| ], | ||
| watchPlugins: [ | ||
| 'jest-watch-typeahead/filename', | ||
| 'jest-watch-typeahead/testname', | ||
| [ | ||
| 'jest-watch-toggle-config', | ||
| { | ||
| setting: 'verbose', | ||
| }, | ||
| ], | ||
| [ | ||
| 'jest-watch-toggle-config', | ||
| { | ||
| setting: 'collectCoverage', | ||
| }, | ||
| ], | ||
| [ | ||
| 'jest-watch-toggle-config', | ||
| { | ||
| setting: 'notify', | ||
| }, | ||
| ], | ||
| [ | ||
| 'jest-watch-toggle-config', | ||
| { | ||
| setting: 'bail', | ||
| }, | ||
| ], | ||
| ], | ||
| collectCoverageFrom: [ | ||
| '<rootDir>/src/**/*.ts', | ||
| ], | ||
| moduleFileExtensions: [ | ||
| 'js', | ||
| 'json', | ||
| 'ts', | ||
| ], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { server } from './__tests__/setup/server'; | ||
|
|
||
| // Establish API mocking before all tests. | ||
| beforeAll(() => server.listen()); | ||
|
|
||
| // Reset any request handlers that we may add during the tests, | ||
| // so they don't affect other tests. | ||
| afterEach(() => server.resetHandlers()); | ||
|
|
||
| // Clean up after the tests are finished. | ||
| afterAll(() => server.close()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, it's not testing too much. We should import the API method from
/Users/marcinkwiatkowski/Sites/vsf/magento2/packages/api-client/src/api/storeConfig/index.tsand test it.For now, is good, I will create a separate task to write a specific API method test case.