Commit 9d3c6c2d authored by Dmytro Zavgorodniy's avatar Dmytro Zavgorodniy

[RNA-761] Add latest utils

parent e272b493
import { drinkInventoryFormatter } from '../formatters'
describe('drinkInventoryFormatter', () => {
const defaultInventory = {}
const defaultExpectedResult = {
batchPrice: undefined,
id: undefined,
price: null,
oldPrice: null,
priceRaw: undefined,
specialPrice: undefined,
priceType: 'notAvailable',
labels: [],
drink: undefined,
note: undefined,
unitSize: undefined,
packageSize: undefined,
externalId: undefined,
}
it('undefined inventory should return undefined', () => {
expect(drinkInventoryFormatter(undefined)).toEqual(undefined)
})
it('null inventory should return null', () => {
expect(drinkInventoryFormatter(null)).toEqual(null)
})
it('emptry inventory should return default result', () => {
expect(drinkInventoryFormatter(defaultInventory)).toEqual(defaultExpectedResult)
})
it('inventory should return correct result', () => {
const inventory = {
special_price: '44.99',
batch_price: [{
price: 24.99,
count: 4,
}],
drink: {
id: 10449,
user_review: [{
id: 2286,
value: 3,
text: 'Nice',
drink_id: 10449,
}],
description: 'Premium brand, bottom fermented Munchner Lager...',
tag: {
name: 'German Lager',
},
name: 'Spaten Premium Lager',
label_url: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
user_favorite: [{
id: 2349,
drink_id: 10449,
}],
avg_review: {
value: 3.54,
count: 493,
},
country: {
name: 'Germany',
description: '',
image_url: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
},
producer: {
id: 1559,
description: '',
name: 'Spaten-Franziskaner-Bräu',
},
drink_type: 'beer',
},
special_price_amount: 24,
value_pick: true,
price: 1.99,
in_stock: 73,
special_price_on: true,
unit_size: '187ML',
note: 'inventory_note',
id: 114929,
pack_size: 3,
staff_pick: true,
external_id: '41520',
on_sale: true,
}
const expectedResult = {
id: 114929,
price: '$1.99',
priceRaw: 1.99,
oldPrice: null,
specialPrice: {
amount: 24,
price: '$44.99',
},
batchPrice: [{
price: 24.99,
count: 4,
}],
priceType: 'specialPrice',
labels: [{
title: '3 PACK',
type: 'packSize',
}, {
title: 'Value Pick',
type: 'valuePick',
}, {
title: 'Staff Pick',
type: 'staffPick',
}, {
title: 'Sale',
type: 'onSale',
}],
drink: {
id: 10449,
logo: {
uri: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
},
title: 'Spaten Premium Lager',
subtitle: 'German Lager, Germany',
description: 'Premium brand, bottom fermented Munchner Lager...',
country: {
description: '',
image_url: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
name: 'Germany',
},
drinkType: 'beer',
producer: {
id: 1559,
description: '',
name: 'Spaten-Franziskaner-Bräu',
},
reviewAvgValue: 3.54,
reviewTotalCount: 493,
userReview: {
id: 2286,
text: 'Nice',
value: 3,
drink_id: 10449,
},
userFavorite: {
id: 2349,
drink_id: 10449,
},
},
note: 'inventory_note',
unitSize: '187ML',
packageSize: 3,
externalId: '41520',
}
expect(drinkInventoryFormatter(inventory)).toEqual(expectedResult)
})
it('should return priceType=outOfStock', () => {
const inventory = {
...defaultInventory,
in_stock: 0,
}
const expectedResult = {
...defaultExpectedResult,
priceType: 'outOfStock',
}
expect(drinkInventoryFormatter(inventory)).toEqual(expectedResult)
})
it('should return priceType=onSale', () => {
const inventory = {
...defaultInventory,
on_sale: true,
}
const expectedResult = {
...defaultExpectedResult,
labels: [{
title: 'Sale',
type: 'onSale',
}],
}
expect(drinkInventoryFormatter(inventory)).toEqual(expectedResult)
})
it('should return priceType=regularPrice', () => {
const inventory = {
...defaultInventory,
price: '1.99',
}
const expectedResult = {
...defaultExpectedResult,
price: '$1.99',
priceRaw: '1.99',
priceType: 'regularPrice',
}
expect(drinkInventoryFormatter(inventory)).toEqual(expectedResult)
})
})
......@@ -35,7 +35,7 @@ describe('getDetailedOrderStatusData', () => {
const order = { order_status: 'approved' }
const expectedResult = {
output: 'approved',
detailedOutputMessage: 'Your order is available for pickup',
detailedOutputMessage: 'Your order is being proccessed',
}
expect(getDetailedOrderStatusData(order)).toEqual(expectedResult)
......@@ -71,6 +71,16 @@ describe('getDetailedOrderStatusData', () => {
expect(getDetailedOrderStatusData(order)).toEqual(expectedResult)
})
it('order_status is pickup_ready', () => {
const order = { order_status: 'pickup_ready' }
const expectedResult = {
output: 'pickupReady',
detailedOutputMessage: 'Your order is available for pickup',
}
expect(getDetailedOrderStatusData(order)).toEqual(expectedResult)
})
it('order_status is canceled_by_user', () => {
const order = { order_status: 'canceled_by_user' }
const expectedResult = {
......
import getOrderProductsCategories from '../getOrderProductsCategories'
describe('getOrderProductsCategories', () => {
it('undefined order products should return default result', () => {
const expectedResult = {
wineCount: 0,
beerCount: 0,
spiritsCount: 0,
otherCount: 0,
}
expect(getOrderProductsCategories(undefined)).toEqual(expectedResult)
})
it('order products should return expected result', () => {
const orderProducts = [{
wine: {},
}, {
drink: {
drink_type: 'beer',
},
}, {
drink: {
drink_type: 'beer',
},
}, {
drink: {
drink_type: 'spirits',
},
}]
const expectedResult = {
wineCount: 1,
beerCount: 2,
spiritsCount: 1,
otherCount: 0,
}
expect(getOrderProductsCategories(orderProducts)).toEqual(expectedResult)
})
})
import handleOrderStatus, {
process,
readyToCollect,
collected,
inTransit,
isActiveOrder,
isNewOrder,
} from '../handleOrderStatus'
describe('handleOrderStatus', () => {
it('undefined order should return error status', () => {
const expectedResult = {
statusImg: {
testUri: '../../../src/utils/handleOrderStatus/img/error.png',
},
statusText: 'Error',
}
expect(handleOrderStatus(undefined)).toEqual(expectedResult)
})
it("order with order_status: 'new' should return process status", () => {
const order = { order_status: 'new' }
const expectedResult = {
statusImg: {
testUri: '../../../src/utils/handleOrderStatus/img/process.png',
},
statusText: 'Process',
}
expect(handleOrderStatus(order)).toEqual(expectedResult)
})
it("order with order_status: 'approved' should return approved status", () => {
const order = { order_status: 'approved' }
const expectedResult = {
statusImg: {
testUri: '../../../src/utils/handleOrderStatus/img/ready_to_collect.png',
},
statusText: 'Approved',
}
expect(handleOrderStatus(order)).toEqual(expectedResult)
})
it("order with order_status: 'delivered' should return collected status", () => {
const order = { order_status: 'delivered' }
const expectedResult = {
statusImg: {
testUri: '../../../src/utils/handleOrderStatus/img/collected.png',
},
statusText: 'Collected',
}
expect(handleOrderStatus(order)).toEqual(expectedResult)
})
it("order with order_status: 'in_transit' should return in transit status", () => {
const order = { order_status: 'in_transit' }
const expectedResult = {
statusImg: {
testUri: '../../../src/utils/handleOrderStatus/img/in_transit.png',
},
statusText: 'In Transit',
}
expect(handleOrderStatus(order)).toEqual(expectedResult)
})
})
describe('process', () => {
it('undefined order should return false', () => {
expect(process(undefined)).toBeFalsy()
})
it('empty order should return false', () => {
expect(process({})).toBeFalsy()
})
it("order with order_status: 'unknown' should return false", () => {
const order = { order_status: 'unknown' }
expect(process(order)).toBeFalsy()
})
it("order with order_status: 'new' should return true", () => {
const order = { order_status: 'new' }
expect(process(order)).toBeTruthy()
})
it("order with order_status: 'placed' should return false", () => {
const order = { order_status: 'placed' }
expect(process(order)).toBeFalsy()
})
it("order with order_status: 'placed' and payment_status: null should return true", () => {
const order = { order_status: 'placed', payment_status: null }
expect(process(order)).toBeTruthy()
})
it("order with order_status: 'placed' and payment_status: 'new' should return true", () => {
const order = { order_status: 'placed', payment_status: 'new' }
expect(process(order)).toBeTruthy()
})
it("order with order_status: 'placed' and payment_status: 'held' should return true", () => {
const order = { order_status: 'placed', payment_status: 'held' }
expect(process(order)).toBeTruthy()
})
})
describe('ready to pickup', () => {
it('undefined order should return false', () => {
expect(readyToCollect(undefined)).toBeFalsy()
})
it('empty order should return false', () => {
expect(readyToCollect({})).toBeFalsy()
})
it("order with order_status: 'unknown' should return false", () => {
const order = { order_status: 'unknown' }
expect(readyToCollect(order)).toBeFalsy()
})
it("order with order_status: 'pickup_ready' should return true", () => {
const order = { order_status: 'pickup_ready' }
expect(readyToCollect(order)).toBeTruthy()
})
})
describe('collected', () => {
it('undefined order should return false', () => {
expect(collected(undefined)).toBeFalsy()
})
it('empty order should return false', () => {
expect(collected({})).toBeFalsy()
})
it("order with order_status: 'unknown' should return false", () => {
const order = { order_status: 'unknown' }
expect(collected(order)).toBeFalsy()
})
it("order with order_status: 'delivered' should return true", () => {
const order = { order_status: 'delivered' }
expect(collected(order)).toBeTruthy()
})
it("order with order_status: 'reconciled' should return true", () => {
const order = { order_status: 'reconciled' }
expect(collected(order)).toBeTruthy()
})
})
describe('inTransit', () => {
it('undefined order should return false', () => {
expect(inTransit(undefined)).toBeFalsy()
})
it('empty order should return false', () => {
expect(inTransit({})).toBeFalsy()
})
it("order with order_status: 'unknown' should return false", () => {
const order = { order_status: 'unknown' }
expect(inTransit(order)).toBeFalsy()
})
it("order with order_status: 'in_transit' should return true", () => {
const order = { order_status: 'in_transit' }
expect(inTransit(order)).toBeTruthy()
})
})
describe('isActiveOrder', () => {
it("order with order_status: 'new' should return true", () => {
const order = { order_status: 'new' }
expect(isActiveOrder(order)).toBeTruthy()
})
it("order with order_status: 'approved' should return true", () => {
const order = { order_status: 'approved' }
expect(isActiveOrder(order)).toBeTruthy()
})
it("order with order_status: 'pickup_ready' should return true", () => {
const order = { order_status: 'pickup_ready' }
expect(isActiveOrder(order)).toBeTruthy()
})
it("order with order_status: 'in_transit' should return true", () => {
const order = { order_status: 'in_transit' }
expect(isActiveOrder(order)).toBeTruthy()
})
})
describe('isNewOrder', () => {
it('undefined order should return false', () => {
expect(isNewOrder(undefined)).toBeFalsy()
})
it('empty order should return false', () => {
expect(isNewOrder({})).toBeFalsy()
})
it("order with order_status: 'unknown' should return false", () => {
const order = { order_status: 'unknown' }
expect(isNewOrder(order)).toBeFalsy()
})
it("order with order_status: 'new' should return false", () => {
const order = { order_status: 'new' }
expect(isNewOrder(order)).toBeTruthy()
})
})
import { userFormatter } from '../formatters'
describe('userFormatter', () => {
it('undefined user should return default result', () => {
const expectedResult = {
firstName: undefined,
lastName: undefined,
fullName: undefined,
profilePicture: undefined,
}
expect(userFormatter(undefined)).toEqual(expectedResult)
})
it('empty user should return default result', () => {
const expectedResult = {
firstName: undefined,
lastName: undefined,
fullName: undefined,
profilePicture: undefined,
profileUsername: undefined,
}
expect(userFormatter({})).toEqual(expectedResult)
})
it('null user should return default result', () => {
const expectedResult = {
firstName: undefined,
lastName: undefined,
fullName: undefined,
profilePicture: undefined,
profileUsername: undefined,
}
expect(userFormatter({})).toEqual(expectedResult)
})
it('user should return expected result', () => {
const user = {
id: 4567,
first_name: 'Dmytro',
last_name: 'Zavgorodniy',
profile_picture: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
}
const expectedResult = {
firstName: 'Dmytro',
lastName: 'Zavgorodniy',
fullName: 'Dmytro Zavgorodniy',
profilePicture: {
uri: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
},
profileUsername: 'Dmytro Zavgorodniy',
}
expect(userFormatter(user)).toEqual(expectedResult)
})
it('user without profile_picture should return expected result', () => {
const user = {
id: 4567,
first_name: 'Dmytro',
last_name: 'Zavgorodniy',
profile_picture: undefined,
}
const expectedResult = {
firstName: 'Dmytro',
lastName: 'Zavgorodniy',
fullName: 'Dmytro Zavgorodniy',
profilePicture: undefined,
profileUsername: 'Dmytro Zavgorodniy',
}
expect(userFormatter(user)).toEqual(expectedResult)
})
it('user without first_name should return expected result', () => {
const user = {
id: 4567,
first_name: undefined,
last_name: 'Zavgorodniy',
profile_picture: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
}
const expectedResult = {
firstName: undefined,
lastName: 'Zavgorodniy',
fullName: 'Zavgorodniy',
profilePicture: {
uri: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
},
profileUsername: 'Zavgorodniy',
}
expect(userFormatter(user)).toEqual(expectedResult)
})
it('user without last_name should return expected result', () => {
const user = {
id: 4567,
first_name: 'Dmytro',
last_name: undefined,
profile_picture: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
}
const expectedResult = {
firstName: 'Dmytro',
lastName: undefined,
fullName: 'Dmytro',
profilePicture: {
uri: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
},
profileUsername: 'Dmytro',
}
expect(userFormatter(user)).toEqual(expectedResult)
})
it('user without first_name and last_name should return expected result', () => {
const user = {
id: 4567,
first_name: undefined,
last_name: undefined,
profile_picture: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
}
const expectedResult = {
firstName: undefined,
lastName: undefined,
fullName: 'User #4567',
profilePicture: {
uri: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
},
profileUsername: undefined,
}
expect(userFormatter(user)).toEqual(expectedResult)
})
it('user with email should return expected result', () => {
const user = {
id: 4567,
first_name: undefined,
last_name: undefined,
email: 'dmytro.zavgorodniy@gmail.com',
profile_picture: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
}
const expectedResult = {
firstName: undefined,
lastName: undefined,
fullName: 'User #4567',
profilePicture: {
uri: 'https://tipsiphotos.s3.amazonaws.com:443/image_upload/image.png',
},
profileUsername: 'dmytro.zavgorodniy@gmail.com',
}
expect(userFormatter(user)).toEqual(expectedResult)
})
})
import { wineInventoryFormatter } from '../formatters'
describe('wineInventoryFormatter', () => {
const defaultInventory = {}
const defaultExpectedResult = {
id: undefined,
price: null,
oldPrice: null,
priceRaw: undefined,
batchPrice: undefined,
specialPrice: undefined,
priceType: 'notAvailable',
labels: [],
wine: undefined,
storeNote: undefined,
unitSize: undefined,
packageSize: undefined,
externalId: undefined,
}
it('undefined inventory should return undefined', () => {
expect(wineInventoryFormatter(undefined)).toEqual(undefined)
})
it('null inventory should return null', () => {
expect(wineInventoryFormatter(null)).toEqual(null)
})
it('emptry inventory should return default result', () => {
expect(wineInventoryFormatter(defaultInventory)).toEqual(defaultExpectedResult)
})
it('inventory should return correct result', () => {
const inventory = {
special_price: '44.99',
batch_price: [{
price: 24.99,
count: 4,
}],
wine: {
name: "Cook's Brut Champagne Blend, Chardonnay",
type: 'sparkling',
batch_price: [{
price: 24.99,
count: 4,
}],
designation: {
name: 'Brut',
description: '',
},
avg_review: {
value: 2.7948717948717947,
count: 39,
},
varietals: [{
name: 'Champagne Blend',
description: 'Champagne is used to...',
}, {
name: 'Chardonnay',
description: 'The flavor of Chardonnay...',
}],
style_scoring: [{
id: 1,
name: 'style_scoring_1',
score: 90,
}, {