This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
219 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -143,6 +143,7 @@ export const OrderFragment = ` | |
orderState | ||
id | ||
version | ||
createdAt | ||
} | ||
`; | ||
|
||
|
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -6,8 +6,19 @@ jest.mock('@vue-storefront/commercetools-api', () => ({ | |
customerSignMeUp: jest.fn(), | ||
customerSignMeIn: jest.fn(), | ||
customerSignOut: jest.fn(), | ||
getMe: () => ({ data: { me: { customer: { firstName: 'loaded customer', | ||
lastName: 'loaded customer' } } } }) | ||
getMe: () => ({ | ||
data: { | ||
me: { | ||
customer: { | ||
firstName: 'loaded customer', | ||
lastName: 'loaded customer' | ||
}, | ||
orders: { | ||
results: [] | ||
} | ||
} | ||
} | ||
}) | ||
})); | ||
|
||
describe('[commercetools-composables] useUser', () => { | ||
|
@@ -16,15 +27,20 @@ describe('[commercetools-composables] useUser', () => { | |
}); | ||
|
||
it('creates properties', () => { | ||
const { loading, error } = useUser(); | ||
const { loading, error, orders } = useUser(); | ||
|
||
expect(loading.value).toEqual(true); | ||
expect(error.value).toEqual(null); | ||
expect(orders.value).toEqual([]); | ||
}); | ||
|
||
it('registers new customer', async () => { | ||
const user = { customer: { firstName: 'john', | ||
lastName: 'doe' } }; | ||
const user = { | ||
customer: { | ||
firstName: 'john', | ||
lastName: 'doe' | ||
} | ||
}; | ||
(customerSignMeUp as any).mockReturnValue(Promise.resolve({ data: { user } })); | ||
|
||
const wrapper = mountComposable(useUser); | ||
|
@@ -40,16 +56,22 @@ describe('[commercetools-composables] useUser', () => { | |
}); | ||
|
||
it('login customer and log out', async () => { | ||
const user = { customer: { firstName: 'john', | ||
lastName: 'doe' } }; | ||
const user = { | ||
customer: { | ||
firstName: 'john', | ||
lastName: 'doe' | ||
} | ||
}; | ||
(customerSignMeIn as any).mockReturnValue(Promise.resolve({ data: { user } })); | ||
|
||
const wrapper = mountComposable(useUser); | ||
await wrapper.vm.$nextTick(); | ||
await wrapper.vm.$nextTick(); | ||
|
||
wrapper.vm.$data.login({ email: '[email protected]', | ||
password: '123' }); | ||
wrapper.vm.$data.login({ | ||
email: '[email protected]', | ||
password: '123' | ||
}); | ||
|
||
expect(wrapper.vm.$data.loading).toBeTruthy(); | ||
await wrapper.vm.$nextTick(); | ||
|
@@ -78,4 +100,12 @@ describe('[commercetools-composables] useUser', () => { | |
lastName: 'loaded customer' | ||
}); | ||
}); | ||
|
||
it('loads current customer with orders', async () => { | ||
const wrapper = mountComposable(useUser); | ||
await wrapper.vm.$nextTick(); | ||
await wrapper.vm.$nextTick(); | ||
expect(wrapper.vm.$data.orders).toEqual([]); | ||
}); | ||
|
||
}); |
This file contains 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
This file contains 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,42 @@ | ||
import { | ||
getOrderDate, | ||
getOrderNumber, | ||
getOrderStatus, | ||
getOrderTotal | ||
} from '../src'; | ||
import { OrderState, Order } from '../src/types/GraphQL'; | ||
|
||
const order: Order = { | ||
createdAt: 123456789, | ||
id: '645ygdf', | ||
orderState: OrderState.Complete, | ||
totalPrice: { | ||
centAmount: 12345, | ||
currencyCode: 'USD' | ||
} | ||
} as any; | ||
|
||
describe('[commercetools-helpers] order helpers', () => { | ||
it('returns default values', () => { | ||
expect(getOrderDate(null)).toBe(''); | ||
expect(getOrderNumber(null)).toBe(''); | ||
expect(getOrderStatus(null)).toBe(''); | ||
expect(getOrderTotal(null)).toBe(null); | ||
}); | ||
|
||
it('returns date', () => { | ||
expect(getOrderDate(order)).toEqual(123456789); | ||
}); | ||
|
||
it('returns order number', () => { | ||
expect(getOrderNumber(order)).toEqual('645ygdf'); | ||
}); | ||
|
||
it('returns status', () => { | ||
expect(getOrderStatus(order)).toEqual(OrderState.Complete); | ||
}); | ||
|
||
it('returns total gross', () => { | ||
expect(getOrderTotal(order)).toEqual(123.45); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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.