summaryrefslogtreecommitdiff
path: root/data-tables/features/steps/json.js
blob: edeb3751a877196c5ccdf36bd3d252406917e12a (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
import { Given, When, Then } from '@cucumber/cucumber'
import assert from 'node:assert/strict'

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) {
  assert.deepEqual(JSON.parse(expected), JSON.parse(this.result))
})