Skip to content

Commit

Permalink
Merge 4ac344f into cd38028
Browse files Browse the repository at this point in the history
  • Loading branch information
junajan committed Feb 23, 2018
2 parents cd38028 + 4ac344f commit 0baecf4
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 53 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,3 @@ notifications:
format: html
on_success: change
on_failure: change
env:
global:
- secure: iytO3AZ1pOvuZ8Mb6F6WqNjFnbxWw5yfadrnN5z43jK+23/YKS04bvcExJJ095L7t9IX9Jes2YfH1nbUm/f0oys3l1K40MDTDP7JvG39AfTHxLezUTrNKLryCI/FbuvIcA3BX1x2KH9FuRO1kmz5zaDQ0paNnn8z1MHU2PqizR0=
- secure: 04u05uQP06WQX0BvFY2RISY/9/Z63c+Tjono6Z4habOvLYtYsfE0rmxEcQkp3PGgRnWlDtYek/2S5XMKAG1Vlhlmv/kRpmp4h9t+SsPwLuYlUu8VI0/ADcOn9nLurFVc95jAtLjXSWTtwq5A92Lqj8Ujzpucr8m3pF9XWRnhLg0=
- secure: dF44muD7/0sSF6D0JV1KaVcgjPp/P/q8Yd2CzC/okP+xYNo5DcZhJGjNoPEtdOleE5/Osj+XWPQZfhQaWfoe1tptdXppEYJlkHvkHgJh7k3OIBKxCWr+1onssxkUIYuWZEKtwF4koxtoUNw1EFsHkfSOEWGpb644wL6aeddDv+k=
6 changes: 3 additions & 3 deletions data/marketplace-types.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name,description,gender,brand,designer,primaryColor,sleeveLength,heelType,sizeShoes,sizeTops,materialComposition
top_and_shirts,Tops & Shirts,x,x,x,x,x,,,size,x
shoes,Shoes,x,x,x,x,,x,size,,x
key,name,description,gender,brand,designer,primaryColor,sleeveLength,heelType,sizeShoes,sizeTops,materialComposition
key1,top_and_shirts,Tops & Shirts,x,x,x,x,x,,,size,x
key2,shoes,Shoes,x,x,x,x,,x,size,,x
1 change: 1 addition & 0 deletions data/sample-product-type-master.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "epic-base"
,"key": "epic-base-key"
,"description": "Basistyp für alle Produkte"
,"attributes": [

Expand Down
3 changes: 2 additions & 1 deletion data/sample-product-type-retailer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "epic-base"
"key": "epic-base-key"
,"name": "epic-base"
,"description": "Basistyp für alle Produkte"
,"attributes": [

Expand Down
12 changes: 6 additions & 6 deletions data/sample-product-types.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name,description,gender,designer,set_longtext,set_gender,set_gender,zone_reference,custom_date,custom_time,custom_datetime,active,age,price
base,Base Product Type,x,,,,,,,,,,,
men,Men Product Type,sex,x,x,,,,,,,,,
women,Woman Product Type,,brand,,x,x,,,,,,,
product_zone_restriction,Product with zone restriction,,,,,,x,,,,,,
product_dates,Product with multiplecustom fields,,,,,,,x,x,x,x,x,x
key,name,description,gender,designer,set_longtext,set_gender,set_gender,zone_reference,custom_date,custom_time,custom_datetime,active,age,price
key1,base,Base Product Type,x,,,,,,,,,,,
key2,men,Men Product Type,sex,x,x,,,,,,,,,
key3,women,Woman Product Type,,brand,,x,x,,,,,,,
key4,product_zone_restriction,Product with zone restriction,,,,,,x,,,,,,
key5,product_dates,Product with multiplecustom fields,,,,,,,x,x,x,x,x,x
226 changes: 226 additions & 0 deletions data/tests/product-types-attributes-all.csv

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions data/tests/product-types.csv

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions features/common.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Show common information for tooling
"""

Scenario: Show general help
When I run `product-type-generator --attributes ../../data/tests/product-types-attributes-boolean-text-number.csv --types ../../data/tests/product-types.csv --target .`
When I run `product-type-generator --attributes ../../data/tests/product-types-attributes-all.csv --types ../../data/tests/product-types.csv --target .`
Then the exit status should be 0
And the output should contain:
"""
Expand Down Expand Up @@ -42,7 +42,7 @@ Feature: Show common information for tooling
"inputHint": "SingleLine"
},
"""
When I run `product-type-update --projectKey nicola --source product-type-boo-txt-num.json`
When I run `product-type-update --projectKey producttype-json-generator-tests --source product-type-boo-txt-num.json`
#Then the exit status should be 0
And the output should contain:
"""
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"optimist": "^0.6.0",
"sphere-node-sdk": "^1.20.0",
"sphere-node-utils": "^0.9.1",
"sphere-product-type-import": "^1.1.0",
"sphere-product-type-import": "^2.0.0",
"underscore": "^1.8.3",
"underscore.string": "^3.3.4"
},
Expand All @@ -69,6 +69,7 @@
"grunt-shell": "^2.1.0",
"istanbul": "^0.4.5",
"mocha": "^3.4.2",
"sinon": "^4.4.0",
"sphere-coffeelint": "git://github.com/sphereio/sphere-coffeelint.git#master",
"tmp": "^0.0.31"
},
Expand Down
8 changes: 7 additions & 1 deletion src/coffee/product-type-generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ class ProductTypeGenerator
productTypeDefinitions = []

for row in types
# enforce the key field - see issue #52
if not row['key']
console.error "[ERR] No key given for productType '#{row['name']}', skipping..."
continue

productTypeDefinition =
name: row['name']
description: row['description']
key: row['key']
attributes: []

for header, value of row
continue if header is 'name' or header is 'description'
continue if header in ['name', 'description', 'key']

if _.isString(value) and value.length > 0
if attributeDefinitions[header]
Expand Down
2 changes: 0 additions & 2 deletions src/coffee/product-type-import.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class ProductTypeImporter
console.log "Importing product types to sphere"
Promise.map data.productTypes, (productType) =>
console.log "Importing product type with name:", productType.name
if productType.name && not productType.key
productType.key = _.slugify(productType.name)
@sphereImporter.importProductType productType
.then (res) ->
console.log "Imported product type", res.name
Expand Down
26 changes: 5 additions & 21 deletions src/spec/integration/product-type-importer.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ argv =
logSilent: true

testProductType = {
"key": "product-type-key",
"name": "top_and_shirts",
"description": "Tops & Shirts",
"attributes": [
Expand Down Expand Up @@ -82,6 +83,9 @@ describe 'ProductTypeImporter', ->
.catch (err) ->
console.error "There was an error while deleting product types", err

afterEach ->
Helper.cleanProject sphereClient

it('should import product type', ->
sphereClient.productTypes.fetch()
.then (res) ->
Expand All @@ -92,29 +96,9 @@ describe 'ProductTypeImporter', ->
sphereClient.productTypes.fetch()
.then (res) ->
expect(res.body.results.length).to.equal 1
expect(res.body.results[0].key).to.equal testProductType.key
).timeout(5000)

it('should import product type and generate key', ->
key = "unslugified name 1928 - "
keySlugified = "unslugified-name-1928"

sphereClient.productTypes.fetch()
.then (res) ->
expect(res.body.results.length).to.equal 0
console.log "Importing product type using importer"

testProductType.name = key
delete testProductType.key

importer.import {productTypes: [testProductType]}
.then ->
sphereClient.productTypes.fetch()
.then (res) ->
expect(res.body.results.length).to.equal 1
productType = res.body.results[0]
expect(productType.key).to.equal keySlugified
).timeout(5000)

it 'should not import wrong product type', (done) ->
delete testProductType.name

Expand Down
31 changes: 29 additions & 2 deletions src/spec/unit/product-type-generator.spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ProductTypeGenerator = require '../../lib/product-type-generator'
{expect} = require 'chai'
sinon = require 'sinon'

describe 'ProductTypeGenerator', ->

Expand All @@ -20,8 +21,6 @@ describe 'ProductTypeGenerator', ->
it 'should return full locale codes and languages for localized property header', ->
expect(@generator._languages('label', ['name', 'label.de', 'label.en-US', 'enumlabel.de', 'enumlabel.en-US', 'enumlabel.it-IT'])).to.deep.equal ['de', 'en-US']



it 'should return an object with localized values', ->

attributeRow =
Expand Down Expand Up @@ -541,10 +540,12 @@ describe 'ProductTypeGenerator', ->
it 'should return an array with product type definitions with mastersku', ->

productTypeDefinition1 =
key: 'key1'
name: 'ProductType1'
description: 'Description1'

productTypeDefinition2 =
key: 'key2'
name: 'ProductType2'
description: 'Description2'

Expand All @@ -564,11 +565,13 @@ describe 'ProductTypeGenerator', ->
attributeDefinitions = []

expectedProductTypeDefinition1 =
key: 'key1'
name: 'ProductType1'
description: 'Description1'
attributes: [mastersku]

expectedProductTypeDefinition2 =
key: 'key2'
name: 'ProductType2'
description: 'Description2'
attributes: [mastersku]
Expand All @@ -580,11 +583,13 @@ describe 'ProductTypeGenerator', ->
it 'should return an array with product type definitions with attributes', ->

productTypeDefinition1 =
key: 'key1'
name: 'ProductType1'
description: 'Description1'
information: 'x'

productTypeDefinition2 =
key: 'key2'
name: 'ProductType2'
description: 'Description2'
size: 'X'
Expand Down Expand Up @@ -631,11 +636,13 @@ describe 'ProductTypeGenerator', ->
information: information

expectedProductTypeDefinition1 =
key: 'key1'
name: 'ProductType1'
description: 'Description1'
attributes: [information, mastersku]

expectedProductTypeDefinition2 =
key: 'key2'
name: 'ProductType2'
description: 'Description2'
attributes: [size, mastersku]
Expand All @@ -647,11 +654,13 @@ describe 'ProductTypeGenerator', ->
it 'should skip product types with unkown product attributes', ->

productTypeDefinition1 =
key: 'key1'
name: 'ProductType1'
description: 'Description1'
unkownAttribute: 'x'

productTypeDefinition2 =
key: 'key2'
name: 'ProductType2'
description: 'Description2'
size: 'x'
Expand All @@ -675,11 +684,13 @@ describe 'ProductTypeGenerator', ->

expectedProductTypeDefinitions = [
{
key: 'key1'
name: 'ProductType1'
description: 'Description1'
attributes: []
},
{
key: 'key2'
name: 'ProductType2'
description: 'Description2'
attributes: [size]
Expand All @@ -691,6 +702,7 @@ describe 'ProductTypeGenerator', ->
it 'should return attribute with product type specific name', ->

productTypeDefinition =
key: 'key'
name: 'myProductType'
description: 'myDescription'
size: 'myAttribName'
Expand All @@ -711,6 +723,7 @@ describe 'ProductTypeGenerator', ->
size: size

expectedProductTypeDefinition =
key: 'key'
name: 'myProductType'
description: 'myDescription'
attributes: [
Expand Down Expand Up @@ -828,3 +841,17 @@ describe 'ProductTypeGenerator', ->
expect(@generator._type('set:set:type')).to.deep.equal 'set'
expect(@generator._type('set:type')).to.deep.equal 'set'
expect(@generator._type('type')).to.deep.equal 'type'

it 'should log an error and skip productTypes without key', ->

errorSpy = sinon.spy console, 'error'
productTypeDefinition =
# missing key
name: 'myProductType'
description: 'myDescription'
size: 'myAttribName'

expect(@generator._createProductTypesDefinitions([productTypeDefinition])).to.deep.equal []
expect(errorSpy.called).to.equal true
expect(errorSpy.args[0][0]).to.equal '[ERR] No key given for productType \'myProductType\', skipping...'
errorSpy.restore()

0 comments on commit 0baecf4

Please sign in to comment.