@labdigital/commercetools-mock 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.9.0",
2
+ "version": "0.9.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -8,10 +8,12 @@ describe('Predicate filter', () => {
8
8
  arrayProperty: ['foo', 'bar', 'nar'],
9
9
  notDefined: undefined,
10
10
  emptyArrayProperty: [],
11
+ booleanProperty: true,
11
12
  nested: {
12
13
  numberProperty: 1234,
13
14
  objectProperty: {
14
15
  stringProperty: 'foobar',
16
+ booleanProperty: true,
15
17
  },
16
18
  },
17
19
 
@@ -31,6 +33,13 @@ describe('Predicate filter', () => {
31
33
  expect(match(`stringProperty=:val`, { val: 'foobar' })).toBeTruthy()
32
34
  })
33
35
 
36
+ test('booleanProperty = true', async () => {
37
+ expect(match(`booleanProperty != true`)).toBeFalsy()
38
+ expect(match(`booleanProperty = true`)).toBeTruthy()
39
+
40
+ expect(match(`booleanProperty=:val`, { val: true })).toBeTruthy()
41
+ })
42
+
34
43
  test('stringProperty matches ignore case "foobar"', async () => {
35
44
  expect(match(`stringProperty="FOObar"`)).toBeFalsy()
36
45
  expect(match(`stringProperty matches ignore case "FOObar"`)).toBeTruthy()
@@ -168,6 +177,13 @@ describe('Predicate filter', () => {
168
177
  ).toBeTruthy()
169
178
  })
170
179
 
180
+ test('nested attribute access', async () => {
181
+ expect(match(`nested(objectProperty(booleanProperty != true))`)).toBeFalsy()
182
+ expect(
183
+ match(`nested(objectProperty(booleanProperty != false))`)
184
+ ).toBeTruthy()
185
+ })
186
+
171
187
  test('lexer confusion', async () => {
172
188
  expect(() => match(`orSomething="foobar"`)).toThrow(PredicateError)
173
189
  expect(() => match(`orSomething="foobar"`)).toThrow(
@@ -124,6 +124,7 @@ const getLexer = (value: string) => {
124
124
  .token('FLOAT', /\d+\.\d+/)
125
125
  .token('INT', /\d+/)
126
126
  .token('VARIABLE', /:([-_A-Za-z0-9]+)/)
127
+ .token('BOOLEAN', /(true|false)/)
127
128
  .token('IDENTIFIER', /[-_A-Za-z0-9]+/)
128
129
  .token('STRING', /"((?:\\.|[^"\\])*)"/)
129
130
  .token('STRING', /'((?:\\.|[^'\\])*)'/)
@@ -159,6 +160,13 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
159
160
  pos: t.token.strpos(),
160
161
  } as Symbol
161
162
  })
163
+ .nud('BOOLEAN', 1, t => {
164
+ return {
165
+ type: 'boolean',
166
+ value: t.token.match === 'true' ? true : false,
167
+ pos: t.token.strpos(),
168
+ } as Symbol
169
+ })
162
170
  .nud('VARIABLE', 100, t => {
163
171
  return {
164
172
  type: 'var',
@@ -254,7 +262,6 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
254
262
  .led('!=', 20, ({ left, bp }) => {
255
263
  const expr = parser.parse({ terminals: [bp - 1] })
256
264
  validateSymbol(expr)
257
-
258
265
  return (obj: any, vars: VariableMap) => {
259
266
  return resolveValue(obj, left) !== resolveSymbol(expr, vars)
260
267
  }