Move add-on related data to GraphQL
Add-on products have data that is currently not reflected in the proper layer. As an entity, it should be modelled properly and not just rely on objects defined "on-the-fly". We want to enforce validation on the properties each add-on should have via the definition of a GraphQL Type.
For this reason, this Issue will move the data related to each add-on item to the Apollo cache. This will help keep the concerns separated as much as possible and reduce some redundant code.
The scope of this issue is the following addon-related fields:
Storage | CI Minutes |
---|---|
I18N_STORAGE_PRODUCT_LABEL | I18N_CI_MINUTES_PRODUCT_LABEL |
I18N_STORAGE_PRODUCT_UNIT | I18N_CI_MINUTES_PRODUCT_UNIT |
STORAGE_PER_PACK | CI_MINUTES_PER_PACK |
hasExpiration : true
|
hasExpiration : false
|
Additionally, an isAddon
property should be added to both, with the value of true
.
Proposal
-
Add/change tests for
BuyAddonsApp
to make sure we have tests in place for Storage and CI Minutes before doing the refactor. Currently the tests are around Storage only, we need to add tests for CI minutes as well. We can also make use of snapshot tests for both Storage and Minutes so we don't have to manually check for every string.- The resolved value for plans has the mocked minutes data as a default value. Current tests use storage config values when creating the component but don't always pass the query mock with storage data. We should pass the query mock for the ones that don't to make sure they use storage addon data instead of the default minutes data for Storage. These will fail when we replace the usages of config with plan in the upcoming MRs as the actual values will be that of minutes rather than storage.
- Make
propsData
a constant (ex.STORAGE_ADDON_PROPS
) in the spec file and pass it while callingcreateComponent
as props to create a component. This way we can have another constant to hold minutes props data and use it when creating a component for CI Minutes - Replace current applicable tests for Storage with snapshot tests and add new tests (including snapshot tests) for CI Minutes
-
Use the current query
getPlans
, and add new fields to be locally resolved (example here). The following are only suggestions for a possible approach: -
Retrieve the info from inside the
BuyAddonsApp
. Now thatplan
is populated with the relevant data, we replace the usages ofconfig
withplan
(check if the properties are matching). Additionally, bring theisAddon
to the data (example here) and remove it from here. -
Remove the const (from the previous table) from the
config
from the following files:
Suggested implementation plan
Step | Description | MR |
---|---|---|
1 | Pass plansQueryMock while calling createMockApolloProvider in the current tests for the tests that don't |
!77920 (merged) |
2 | Make propsData a constant and pass in while calling createComponent
|
!77920 (merged) |
3 | Replace current tests for Storage with snapshots | !78032 (merged) |
4 | Add snapshot tests for CI Minutes | !78032 (merged) |
5 | Move new fields to Apollo cache | !78426 (merged) |
6 | Replace config usages with new fields in plan and remove the corresponding constants from config
|
!78436 (merged) |
Steps 1 & 2 can be done in the same MR if they are too simple to be in separate MRs.