Skip to content

Commit

Permalink
Merge branch 'main' into chore/admin-template
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielHosino committed Jan 17, 2022
2 parents 7d3bdb4 + e917b7e commit 1e1f0bd
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Add initial admin development

## [0.20.0] - 2022-01-17

### Updated

- setAffiliateOnOrderForm mutation to respond with the mutated orderform
- AffiliateValidator component to update OrderFormContext with customData after mutation

## [0.19.0] - 2022-01-14

### Added
Expand Down
2 changes: 1 addition & 1 deletion graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ type Query {
}

type Mutation {
setAffiliateOnOrderForm(affiliateId: String, orderFormId: String): Boolean
setAffiliateOnOrderForm(affiliateId: String, orderFormId: String): OrderForm
}
15 changes: 15 additions & 0 deletions graphql/types/OrderForm.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type OrderForm {
customData: CustomData
}

type CustomData {
customApps: [CustomApp!]!
}

scalar CustomFieldsObject

type CustomApp {
id: ID!
major: Int!
fields: CustomFieldsObject!
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "affiliates",
"vendor": "vtex",
"version": "0.19.0",
"version": "0.20.0",
"title": "Affiliates",
"description": "App that adds support for affiliates on IO stores",
"mustUpdateAt": "2018-01-04",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ describe('setAffiliateOnOrderForm resolver', () => {
checkout: {
setSingleCustomData: jest
.fn()
.mockRejectedValueOnce(new Error('error')),
.mockRejectedValueOnce(
new Error('Error setting affiliate on order form')
),
},
},
vtex: {
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
"lint": "tsc --noEmit --pretty",
"test": "vtex-test-tools test --collectCoverage"
},
"version": "0.19.0"
"version": "0.20.0"
}
4 changes: 1 addition & 3 deletions node/resolvers/setAffiliateOnOrderForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const setAffiliateOnOrderForm = async (
}

try {
await checkout.setSingleCustomData(
return checkout.setSingleCustomData(
orderFormId,
{
appId: APP_CUSTOM_DATA.id,
Expand All @@ -31,8 +31,6 @@ export const setAffiliateOnOrderForm = async (
},
'AUTH_TOKEN'
)

return true
} catch (err) {
logger.error({
metric: 'set-affiliate-on-orderform',
Expand Down
5 changes: 4 additions & 1 deletion react/AffiliateValidator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ type Props = {
const AffiliateValidator: FC<Props> = ({ Invalid, Valid }) => {
const {
orderForm: { id: orderFormId },
setOrderForm,
} = useOrderForm()

const slug = useMemo(() => {
return getSlug()
}, [])

const [setAffiliateOnOrderForm, { called: mutationHasBeenCalled }] =
useMutation(SET_ON_ORDER_FORM_MUTATION)
useMutation(SET_ON_ORDER_FORM_MUTATION, {
onCompleted: (data) => setOrderForm(data.setAffiliateOnOrderForm),
})

const { data, error } = useQuery<IsAffiliateValidQueryResult>(
IS_AFFILIATE_VALID_QUERY,
Expand Down
15 changes: 14 additions & 1 deletion react/__mocks__/setOnOrderFormMutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ export const mocks = [
},
result: jest.fn(() => ({
data: {
setAffiliateOnOrderForm: true,
setAffiliateOnOrderForm: {
id: 'mockedOrderFormId',
customData: {
customApps: [
{
fields: {
affiliateId: 'validId',
},
id: 'mockedAppId',
major: 1,
},
],
},
},
},
})),
},
Expand Down
3 changes: 3 additions & 0 deletions react/__mocks__/vtex.order-manager/OrderForm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export const setOrderFormSpy = jest.fn()

export const useOrderForm = () => {
return {
orderForm: { id: 'mockedOrderFormId' },
setOrderForm: setOrderFormSpy,
}
}
10 changes: 10 additions & 0 deletions react/__tests__/AffiliateValidator.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MockedProvider, wait } from '@apollo/react-testing'

import { mocks as queryMocks } from '../__mocks__/isAffiliateValidQuery'
import { mocks as mutationMocks } from '../__mocks__/setOnOrderFormMutation'
import { setOrderFormSpy } from '../__mocks__/vtex.order-manager/OrderForm'
import AffiliateValidator from '../AffiliateValidator'

describe('Affiliate Validator', () => {
Expand Down Expand Up @@ -64,4 +65,13 @@ describe('Affiliate Validator', () => {

expect(mutationSpy).toHaveBeenCalled()
})

it('Should update OrderFormContext after sucessfully calling the mutation', async () => {
await renderTest('/validId')

const mutationMockedResult =
mutationMocks[0].result().data.setAffiliateOnOrderForm

expect(setOrderFormSpy).toHaveBeenCalledWith(mutationMockedResult)
})
})
13 changes: 12 additions & 1 deletion react/graphql/setAffiliateOnOrderForm.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
mutation setAffiliateOnOrderForm($affiliateId: String, $orderFormId: String) {
setAffiliateOnOrderForm(affiliateId: $affiliateId, orderFormId: $orderFormId)
setAffiliateOnOrderForm(
affiliateId: $affiliateId
orderFormId: $orderFormId
) {
customData {
customApps {
fields
id
major
}
}
}
}
4 changes: 2 additions & 2 deletions react/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "vtex.affiliates",
"version": "0.19.0",
"version": "0.20.0",
"scripts": {
"test": "vtex-test-tools test"
"test": "vtex-test-tools test --collectCoverage"
},
"dependencies": {
"@vtex/admin-ui": "^0.117.1-next.1",
Expand Down

0 comments on commit 1e1f0bd

Please sign in to comment.