Skip to content

Commit

Permalink
Merge c88cdd8 into f0381e3
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetoz committed Mar 24, 2020
2 parents f0381e3 + c88cdd8 commit e0b2bbd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coffee/sync/utils/product.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ProductUtils extends BaseUtils
# match variant against variants in list - match first by sku, then by key and then by id
findVariantInList: (variant, variantList, attributeToMatchBy) ->
if (attributeToMatchBy)
return @matchesBy(attributeToMatchBy)
return variantList.find((oldVariant) => @matchesBy(variant, oldVariant, attributeToMatchBy))
else
return variantList.find((oldVariant) => @matchesBySku(variant, oldVariant)) or
variantList.find((oldVariant) => @matchesByKey(variant, oldVariant)) or
Expand Down
52 changes: 52 additions & 0 deletions src/spec/sync/utils/product.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,58 @@ describe 'ProductUtils', ->
foundVariant = @utils.findVariantInList(variant, variantList, 'sku')
expect(foundVariant).not.toBeDefined()

it 'should match variants with sku', ->
variant = {
id: 2,
sku: 'sku2'
}
variantList = [
{
id: 1,
sku: 'sku1'
},
{
id: 3,
sku: 'sku2'
}
]
foundVariant = @utils.findVariantInList(variant, variantList, 'sku')
expect(foundVariant).toEqual({ id: 3, sku: 'sku2' })

it 'should match variants with keys', ->
variant = {
id: 2,
key: 'key2'
}
variantList = [
{
id: 1,
key: 'key1'
},
{
id: 3,
key: 'key2'
}
]
foundVariant = @utils.findVariantInList(variant, variantList, 'key')
expect(foundVariant).toEqual({ id: 3, key: 'key2' })

it 'should match variants with ids', ->
variant = {
id: 2
}
variantList = [
{
id: 1
},
{
id: 2
}
]
foundVariant = @utils.findVariantInList(variant, variantList, 'id')
expect(foundVariant).toEqual({ id: 2 })


describe ':: buildVariantPriceActions', ->

it 'should return an empty array when no price diff is provided', ->
Expand Down

0 comments on commit e0b2bbd

Please sign in to comment.