summaryrefslogtreecommitdiff
path: root/data-tables/features/steps/json.js
blob: cd61a8bf7cda0bef136f8a15b827340bc2833718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'

Given('the following books by Simon Frank are in the collection:', function (dataTable) {
  this.objects = []
  dataTable.hashes().forEach(el => {
    this.objects.push({
      id: parseInt(el.id),
      title: el.title
    })
  })
})

Given('the following books by Søren Kierkegaard are in the collection:', function (dataTable) {
  this.objects = []
  dataTable.rows().forEach(el => {
    this.objects.push({
      id: parseInt(el[0]),
      title: el[1]
    })
  })
})

Given('the following book is in the collection:', function (dataTable) {
  const data = dataTable.rowsHash()
  this.objects = {
    id: parseInt(data.id),
    title: data.title,
    author: data.author
  }
})

Given('the following books are in the collection:', function (dataTable) {
  this.objects = []
  dataTable.raw().forEach(el => {
    this.objects.push({
      author: el[0],
      title: el[1]
    })
  })
})

When('I stringify it', function () {
  this.result = JSON.stringify(this.objects)
})

Then('I should get:', function (expected) {
  expect(JSON.parse(expected))
    .to.deep.equal(JSON.parse(this.result))
})