All files / json-cli/test op.remove.tests.json.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 0/0
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91    2x                                                                                                                                                                             2x  
import type {TestCase} from './types';
 
const testCases: TestCase[] = [
  {
    comment: 'Can remove object at root',
    doc: {foo: 'bar'},
    patch: [{op: 'remove', path: ''}],
    expected: null,
  },
  {
    comment: 'Can remove array at root',
    doc: [1, true, false],
    patch: [{op: 'remove', path: ''}],
    expected: null,
  },
  {
    comment: 'Can remove string at root',
    doc: 'Hello world!',
    patch: [{op: 'remove', path: ''}],
    expected: null,
  },
  {
    comment: 'Can remove first level object key',
    doc: {good: 'bad', up: 'down'},
    patch: [{op: 'remove', path: '/up'}],
    expected: {good: 'bad'},
  },
  {
    comment: 'Can remove second level object key',
    doc: {good: 'bad', up: {here: 'there', hmm: [1, 2, 3]}},
    patch: [{op: 'remove', path: '/up/here'}],
    expected: {good: 'bad', up: {hmm: [1, 2, 3]}},
  },
  {
    comment: 'Can remove array element at third level',
    doc: {good: 'bad', up: {here: 'there', hmm: [1, 2, 3]}},
    patch: [{op: 'remove', path: '/up/hmm/1'}],
    expected: {good: 'bad', up: {here: 'there', hmm: [1, 3]}},
  },
  {
    comment: 'Can remove array element in first position',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/0'}],
    expected: {cola: 'coca', arr: ['2', true, null, {}]},
  },
  {
    comment: 'Can remove array element in second position',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/1'}],
    expected: {cola: 'coca', arr: [1, true, null, {}]},
  },
  {
    comment: 'Can remove array element in third position',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/2'}],
    expected: {cola: 'coca', arr: [1, '2', null, {}]},
  },
  {
    comment: 'Can remove array element in fourth position',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/3'}],
    expected: {cola: 'coca', arr: [1, '2', true, {}]},
  },
  {
    comment: 'Can remove array element in fifth position',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/4'}],
    expected: {cola: 'coca', arr: [1, '2', true, null]},
  },
  {
    comment: 'Throws error when removing array element out of bounds',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/5'}],
    error: 'NOT_FOUND',
  },
  {
    comment: 'Throws error when removing array element at negative index "-2"',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/-2'}],
    error: 'INVALID_INDEX',
  },
  {
    comment: 'Throws error when removing array element at string index "str"',
    doc: {cola: 'coca', arr: [1, '2', true, null, {}]},
    patch: [{op: 'remove', path: '/arr/str'}],
    error: 'INVALID_INDEX',
  },
];
 
export default testCases;