Skip to content

Commit

Permalink
fix(tests): Fix cleaning project before tests
Browse files Browse the repository at this point in the history
  • Loading branch information
junajan committed May 31, 2017
1 parent f6f8382 commit 3c903f6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
27 changes: 27 additions & 0 deletions src/spec/helper/helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,30 @@ exports.createReader = (fileType, delimiter = ',', encoding = 'utf-8' ) ->
csvDelimiter: delimiter,
encoding: encoding,
importFormat: fileType,

exports.unpublishAllProducts = (client) ->
client.productProjections
.where 'published=true'
.perPage 200
.process (res) ->
Promise.map res.body.results, (item) ->
client.products
.byId item.id
.update
version: item.version
actions: [{
action: 'unpublish'
}]
, { concurrency: 10 }

exports.deleteAllProducts = (client) ->
exports.unpublishAllProducts client
.then ->
client.products
.perPage 200
.process (res) ->
Promise.map res.body.results, (item) ->
client.products
.byId item.id
.delete item.version
, { concurrency: 10 }
19 changes: 11 additions & 8 deletions src/spec/integration/product-type-importer.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Promise = require 'bluebird'
ProductTypeImporter = require '../../lib/product-type-import'
{SphereClient} = require 'sphere-node-sdk'
{ProjectCredentialsConfig} = require 'sphere-node-utils'
Helper = require '../helper/helper'

errMissingCredentials = 'Missing configuration in env variable named SPHERE_PROJECT_KEY'

Expand Down Expand Up @@ -75,14 +76,16 @@ describe 'ProductTypeImporter', ->
# increase timeout so we will have time to delete all previous product types
this.timeout 60000

sphereClient.productTypes
.perPage(50)
.process (res) ->
console.log "Deleting old product types", res.body.results.length
Promise.map res.body.results, (productType) ->
sphereClient.productTypes.byId(productType.id)
.delete(productType.version)
, concurrency: 10
Helper.deleteAllProducts sphereClient
.then ->
sphereClient.productTypes
.perPage(50)
.process (res) ->
console.log "Deleting old product types", res.body.results.length
Promise.map res.body.results, (productType) ->
sphereClient.productTypes.byId(productType.id)
.delete(productType.version)
, concurrency: 10
.then ->
console.log "Product types were deleted"
.catch (err) ->
Expand Down

0 comments on commit 3c903f6

Please sign in to comment.