How to use expectedValues method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

convert-to-form.spec.ts

Source:convert-to-form.spec.ts Github

copy

Full Screen

1import { BuildConfig, BuildConfigRunPolicy, BuildStrategyType } from '../../types';2import { convertBuildConfigToFormData } from '../convert-to-form';3import { getInitialBuildConfigFormikValues } from '../initial-data';4describe('convertBuildConfigToFormData', () => {5 it('keeps all initial form data with minimal BuildConfig', () => {6 const buildConfig: BuildConfig = {7 apiVersion: 'build.openshift.io/v1',8 kind: 'BuildConfig',9 metadata: {},10 spec: {},11 };12 const expectedValues = getInitialBuildConfigFormikValues();13 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);14 });15 it('keeps all initial form data with null BuildConfig', () => {16 const buildConfig = null as BuildConfig;17 const expectedValues = getInitialBuildConfigFormikValues();18 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);19 });20 describe('name section', () => {21 it('sets resource name in form data when BuildConfig has a name', () => {22 const buildConfig: BuildConfig = {23 apiVersion: 'build.openshift.io/v1',24 kind: 'BuildConfig',25 metadata: {26 name: 'a-buildconfig',27 },28 spec: {},29 };30 const expectedValues = getInitialBuildConfigFormikValues();31 expectedValues.formData.name = 'a-buildconfig';32 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);33 });34 });35 describe('source section', () => {36 it('sets git source in form data when BuildConfig has a git resource without context dir', () => {37 const buildConfig: BuildConfig = {38 apiVersion: 'build.openshift.io/v1',39 kind: 'BuildConfig',40 metadata: {},41 spec: {42 source: {43 type: 'Git',44 git: {45 uri: 'https://github.com/openshift/ruby-ex.git',46 ref: 'master',47 },48 },49 },50 };51 const expectedValues = getInitialBuildConfigFormikValues();52 expectedValues.formData.source.type = 'git';53 expectedValues.formData.source.git.git.url = 'https://github.com/openshift/ruby-ex.git';54 expectedValues.formData.source.git.git.ref = 'master';55 expectedValues.formData.source.git.git.dir = '';56 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);57 });58 it('sets git source in form data when BuildConfig has a git resource with context dir', () => {59 const buildConfig: BuildConfig = {60 apiVersion: 'build.openshift.io/v1',61 kind: 'BuildConfig',62 metadata: {},63 spec: {64 source: {65 type: 'Git',66 git: {67 uri: 'https://github.com/openshift/ruby-ex.git',68 ref: 'master',69 },70 contextDir: '/another-folder',71 },72 },73 };74 const expectedValues = getInitialBuildConfigFormikValues();75 expectedValues.formData.source.type = 'git';76 expectedValues.formData.source.git.git.url = 'https://github.com/openshift/ruby-ex.git';77 expectedValues.formData.source.git.git.ref = 'master';78 expectedValues.formData.source.git.git.dir = '/another-folder';79 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);80 });81 it('sets git secret in form data when BuildConfig has a git resource with a secret', () => {82 const buildConfig: BuildConfig = {83 apiVersion: 'build.openshift.io/v1',84 kind: 'BuildConfig',85 metadata: {},86 spec: {87 source: {88 type: 'Git',89 git: {90 uri: 'https://github.com/openshift/ruby-ex.git',91 ref: 'master',92 },93 sourceSecret: {94 name: 'github-secret',95 },96 },97 },98 };99 const expectedValues = getInitialBuildConfigFormikValues();100 expectedValues.formData.source.type = 'git';101 expectedValues.formData.source.git.git.url = 'https://github.com/openshift/ruby-ex.git';102 expectedValues.formData.source.git.git.ref = 'master';103 expectedValues.formData.source.git.git.dir = '';104 expectedValues.formData.source.git.git.secret = 'github-secret';105 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);106 });107 it('sets dockerfile source in form data when BuildConfig has a dockerfile resource', () => {108 const buildConfig: BuildConfig = {109 apiVersion: 'build.openshift.io/v1',110 kind: 'BuildConfig',111 metadata: {},112 spec: {113 source: {114 type: 'Dockerfile',115 dockerfile: 'FROM centos\nRUN echo hello world',116 },117 },118 };119 const expectedValues = getInitialBuildConfigFormikValues();120 expectedValues.formData.source.type = 'dockerfile';121 expectedValues.formData.source.dockerfile = 'FROM centos\nRUN echo hello world';122 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);123 });124 });125 describe('images section', () => {126 it('sets image build-from correctly based on BuildConfig sourceStrategy', () => {127 const buildConfig: BuildConfig = {128 apiVersion: 'build.openshift.io/v1',129 kind: 'BuildConfig',130 metadata: {131 namespace: 'a-namespace',132 },133 spec: {134 strategy: {135 type: 'Source',136 sourceStrategy: {137 from: {138 kind: 'ImageStreamTag',139 namespace: 'openshift',140 name: 'ruby:2.7',141 },142 },143 },144 },145 };146 const expectedValues = getInitialBuildConfigFormikValues();147 expectedValues.formData.source.git.project.name = 'a-namespace';148 expectedValues.formData.images.strategyType = BuildStrategyType.Source;149 expectedValues.formData.images.buildFrom.type = 'imageStreamTag';150 expectedValues.formData.images.buildFrom.imageStreamTag.fromImageStreamTag = true;151 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.namespace = 'openshift';152 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.image = 'ruby';153 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.tag = '2.7';154 expectedValues.formData.images.buildFrom.imageStreamTag.project.name = 'openshift';155 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);156 });157 it('sets image push-to with BuildConfig namespace based on BuildConfig output', () => {158 const buildConfig: BuildConfig = {159 apiVersion: 'build.openshift.io/v1',160 kind: 'BuildConfig',161 metadata: {162 namespace: 'a-namespace',163 },164 spec: {165 output: {166 to: {167 kind: 'ImageStreamTag',168 name: 'nodejs-ex-git:latest',169 },170 },171 },172 };173 const expectedValues = getInitialBuildConfigFormikValues();174 expectedValues.formData.source.git.project.name = 'a-namespace';175 expectedValues.formData.images.pushTo.type = 'imageStreamTag';176 expectedValues.formData.images.pushTo.imageStreamTag.fromImageStreamTag = true;177 expectedValues.formData.images.pushTo.imageStreamTag.imageStream.namespace = 'a-namespace';178 expectedValues.formData.images.pushTo.imageStreamTag.imageStream.image = 'nodejs-ex-git';179 expectedValues.formData.images.pushTo.imageStreamTag.imageStream.tag = 'latest';180 expectedValues.formData.images.pushTo.imageStreamTag.project.name = 'a-namespace';181 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);182 });183 });184 describe('environment variables section', () => {185 it('sets environment variables based on BuildConfig strategy > sourceStrategy', () => {186 const buildConfig: BuildConfig = {187 apiVersion: 'build.openshift.io/v1',188 kind: 'BuildConfig',189 metadata: {},190 spec: {191 strategy: {192 type: 'Source',193 sourceStrategy: {194 from: {195 kind: 'ImageStreamTag',196 namespace: 'openshift',197 name: 'ruby:2.7',198 },199 env: [200 { name: 'env key 1', value: 'env value 1' },201 { name: 'env key 2', value: 'env value 2' },202 ],203 },204 },205 },206 };207 const expectedValues = getInitialBuildConfigFormikValues();208 expectedValues.formData.images.strategyType = BuildStrategyType.Source;209 expectedValues.formData.images.buildFrom.type = 'imageStreamTag';210 expectedValues.formData.images.buildFrom.imageStreamTag.fromImageStreamTag = true;211 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.namespace = 'openshift';212 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.image = 'ruby';213 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.tag = '2.7';214 expectedValues.formData.images.buildFrom.imageStreamTag.project.name = 'openshift';215 expectedValues.formData.environmentVariables = [216 { name: 'env key 1', value: 'env value 1' },217 { name: 'env key 2', value: 'env value 2' },218 ];219 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);220 });221 it('sets environment variables based on BuildConfig strategy > dockerStrategy', () => {222 const buildConfig: BuildConfig = {223 apiVersion: 'build.openshift.io/v1',224 kind: 'BuildConfig',225 metadata: {},226 spec: {227 strategy: {228 type: 'Docker',229 dockerStrategy: {230 dockerfilePath: 'Dockerfile',231 env: [232 { name: 'env key 1', value: 'env value 1' },233 { name: 'env key 2', value: 'env value 2' },234 ],235 },236 },237 },238 };239 const expectedValues = getInitialBuildConfigFormikValues();240 expectedValues.formData.images.strategyType = BuildStrategyType.Docker;241 expectedValues.formData.environmentVariables = [242 { name: 'env key 1', value: 'env value 1' },243 { name: 'env key 2', value: 'env value 2' },244 ];245 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);246 });247 it('sets environment variable configmap based on BuildConfig strategy > sourceStrategy', () => {248 const buildConfig: BuildConfig = {249 apiVersion: 'build.openshift.io/v1',250 kind: 'BuildConfig',251 metadata: {},252 spec: {253 strategy: {254 type: 'Source',255 sourceStrategy: {256 from: {257 kind: 'ImageStreamTag',258 namespace: 'openshift',259 name: 'ruby:2.7',260 },261 env: [262 { name: 'env key 1', value: 'env value 1' },263 {264 name: 'env 2',265 valueFrom: {266 configMapKeyRef: { name: 'default-token-g4vc4', key: 'service-ca.crt' },267 },268 },269 ],270 },271 },272 },273 };274 const expectedValues = getInitialBuildConfigFormikValues();275 expectedValues.formData.images.strategyType = BuildStrategyType.Source;276 expectedValues.formData.images.buildFrom.type = 'imageStreamTag';277 expectedValues.formData.images.buildFrom.imageStreamTag.fromImageStreamTag = true;278 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.namespace = 'openshift';279 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.image = 'ruby';280 expectedValues.formData.images.buildFrom.imageStreamTag.imageStream.tag = '2.7';281 expectedValues.formData.images.buildFrom.imageStreamTag.project.name = 'openshift';282 expectedValues.formData.environmentVariables = [283 { name: 'env key 1', value: 'env value 1' },284 {285 name: 'env 2',286 valueFrom: {287 configMapKeyRef: { name: 'default-token-g4vc4', key: 'service-ca.crt' },288 },289 },290 ];291 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);292 });293 it('sets environment variable secret based on BuildConfig strategy > dockerStrategy', () => {294 const buildConfig: BuildConfig = {295 apiVersion: 'build.openshift.io/v1',296 kind: 'BuildConfig',297 metadata: {},298 spec: {299 strategy: {300 type: 'Docker',301 dockerStrategy: {302 dockerfilePath: 'Dockerfile',303 env: [304 { name: 'env key 1', value: 'env value 1' },305 {306 name: 'env 2',307 valueFrom: {308 secretKeyRef: { name: 'default-token-g4vc4', key: 'service-ca.crt' },309 },310 },311 ],312 },313 },314 },315 };316 const expectedValues = getInitialBuildConfigFormikValues();317 expectedValues.formData.images.strategyType = BuildStrategyType.Docker;318 expectedValues.formData.environmentVariables = [319 { name: 'env key 1', value: 'env value 1' },320 {321 name: 'env 2',322 valueFrom: {323 secretKeyRef: { name: 'default-token-g4vc4', key: 'service-ca.crt' },324 },325 },326 ];327 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);328 });329 });330 describe('triggers section', () => {331 it('sets config change and two other triggers based on BuildConfig triggers', () => {332 const buildConfig: BuildConfig = {333 apiVersion: 'build.openshift.io/v1',334 kind: 'BuildConfig',335 metadata: {},336 spec: {337 triggers: [338 { type: 'ConfigChange' },339 { type: 'Generic', generic: { secret: '19a3' } },340 { type: 'GitHub', github: { secret: '2cd4' } },341 ],342 },343 };344 const expectedValues = getInitialBuildConfigFormikValues();345 expectedValues.formData.triggers.configChange = true;346 expectedValues.formData.triggers.imageChange = false;347 expectedValues.formData.triggers.otherTriggers = [348 { type: 'Generic', secret: '19a3' },349 { type: 'GitHub', secret: '2cd4' },350 ];351 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);352 });353 it('sets image change and two other triggers based on BuildConfig triggers', () => {354 const buildConfig: BuildConfig = {355 apiVersion: 'build.openshift.io/v1',356 kind: 'BuildConfig',357 metadata: {},358 spec: {359 triggers: [360 { type: 'ImageChange', imageChange: { lastTriggeredImageID: '1234' } },361 { type: 'Generic', generic: { secret: '19a3' } },362 { type: 'GitHub', github: { secret: '2cd4' } },363 ],364 },365 };366 const expectedValues = getInitialBuildConfigFormikValues();367 expectedValues.formData.triggers.configChange = false;368 expectedValues.formData.triggers.imageChange = true;369 expectedValues.formData.triggers.otherTriggers = [370 { type: 'Generic', secret: '19a3' },371 { type: 'GitHub', secret: '2cd4' },372 ];373 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);374 });375 });376 describe('secrets section', () => {377 it('sets the form secrets when BuildConfig source contains some secrets', () => {378 const buildConfig: BuildConfig = {379 apiVersion: 'build.openshift.io/v1',380 kind: 'BuildConfig',381 metadata: {},382 spec: {383 source: {384 type: 'Dockerfile',385 dockerfile: 'FROM: centos\nRUN echo hello world',386 secrets: [{ secret: { name: 'buildsecret' }, destinationDir: 'secretdest' }],387 },388 },389 };390 const expectedValues = getInitialBuildConfigFormikValues();391 expectedValues.formData.source.type = 'dockerfile';392 expectedValues.formData.source.dockerfile = 'FROM: centos\nRUN echo hello world';393 expectedValues.formData.secrets = [{ secret: 'buildsecret', mountPoint: 'secretdest' }];394 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);395 });396 });397 describe('policy section', () => {398 it('sets no default runPolicy (use null) when BuildConfig runPolicy is not defined', () => {399 const buildConfig: BuildConfig = {400 apiVersion: 'build.openshift.io/v1',401 kind: 'BuildConfig',402 metadata: {},403 spec: {},404 };405 const expectedValues = getInitialBuildConfigFormikValues();406 expectedValues.formData.policy.runPolicy = null;407 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);408 });409 it('sets a non default runPolicy based on BuildConfig runPolicy', () => {410 const buildConfig: BuildConfig = {411 apiVersion: 'build.openshift.io/v1',412 kind: 'BuildConfig',413 metadata: {},414 spec: {415 runPolicy: BuildConfigRunPolicy.SerialLatestOnly,416 },417 };418 const expectedValues = getInitialBuildConfigFormikValues();419 expectedValues.formData.policy.runPolicy = BuildConfigRunPolicy.SerialLatestOnly;420 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);421 });422 });423 describe('hooks section', () => {424 it('sets the hook command when BuildConfig postCommit has just a command', () => {425 const buildConfig: BuildConfig = {426 apiVersion: 'build.openshift.io/v1',427 kind: 'BuildConfig',428 metadata: {},429 spec: {430 postCommit: {431 command: ['echo', 'hello', 'world'],432 },433 },434 };435 const expectedValues = getInitialBuildConfigFormikValues();436 expectedValues.formData.hooks.enabled = true;437 expectedValues.formData.hooks.type = 'command';438 expectedValues.formData.hooks.commands = ['echo', 'hello', 'world'];439 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);440 });441 it('sets the hook command and arguments when BuildConfig postCommit has command and arguments', () => {442 const buildConfig: BuildConfig = {443 apiVersion: 'build.openshift.io/v1',444 kind: 'BuildConfig',445 metadata: {},446 spec: {447 postCommit: {448 command: ['echo'],449 args: ['hello', 'world'],450 },451 },452 };453 const expectedValues = getInitialBuildConfigFormikValues();454 expectedValues.formData.hooks.enabled = true;455 expectedValues.formData.hooks.type = 'command';456 expectedValues.formData.hooks.commands = ['echo'];457 expectedValues.formData.hooks.arguments = ['hello', 'world'];458 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);459 });460 it('sets the hook shell with arguments when BuildConfig postCommit has a script', () => {461 const buildConfig: BuildConfig = {462 apiVersion: 'build.openshift.io/v1',463 kind: 'BuildConfig',464 metadata: {},465 spec: {466 postCommit: {467 script: '#!/bin/bash\necho $*',468 args: ['hello', 'world'],469 },470 },471 };472 const expectedValues = getInitialBuildConfigFormikValues();473 expectedValues.formData.hooks.enabled = true;474 expectedValues.formData.hooks.type = 'shell';475 expectedValues.formData.hooks.shell = '#!/bin/bash\necho $*';476 expectedValues.formData.hooks.arguments = ['hello', 'world'];477 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);478 });479 it('sets the onlyArgs option when BuildConfig postCommit has just arguments', () => {480 const buildConfig: BuildConfig = {481 apiVersion: 'build.openshift.io/v1',482 kind: 'BuildConfig',483 metadata: {},484 spec: {485 postCommit: {486 args: ['hello', 'world'],487 },488 },489 };490 const expectedValues = getInitialBuildConfigFormikValues();491 expectedValues.formData.hooks.enabled = true;492 expectedValues.formData.hooks.type = 'onlyArgs';493 expectedValues.formData.hooks.arguments = ['hello', 'world'];494 expect(convertBuildConfigToFormData(buildConfig)).toEqual(expectedValues);495 });496 });...

Full Screen

Full Screen

test-value-provider-spec.js

Source:test-value-provider-spec.js Github

copy

Full Screen

1/* jshint node:true, expr:true */2'use strict';3var _chai = require('chai');4_chai.use(require('sinon-chai'));5_chai.use(require('chai-as-promised'));6var expect = _chai.expect;7var _testValueProvider = require('../../lib/test-value-provider');8describe('testValueProvider', () => {9 function _getExpectedValues() {10 return {11 primitives: [ undefined, null, 123, 'abc', true ],12 complex: [ 'object', 'array', 'function' ]13 };14 }15 function _checkResults(values, expectedValues) {16 expectedValues.extra = expectedValues.extra || [];17 expectedValues.primitives.forEach((item, index) => {18 expect(values[index]).to.equal(item);19 });20 let baseIndex = expectedValues.primitives.length;21 expect(values).to.be.an('array');22 expectedValues.complex.forEach((itemType, index) => {23 expect(values[baseIndex + index]).to.be.an(itemType);24 if(itemType !== 'function') {25 expect(values[index + baseIndex]).to.be.empty;26 }27 });28 baseIndex += expectedValues.complex.length;29 expectedValues.extra.forEach((item, index) => {30 expect(values[baseIndex + index]).to.equal(item);31 });32 }33 it('should expose methods required by the interface', function() {34 expect(_testValueProvider.allButSelected).to.be.a('function');35 expect(_testValueProvider.allButString).to.be.a('function');36 expect(_testValueProvider.allButNumber).to.be.a('function');37 expect(_testValueProvider.allButObject).to.be.a('function');38 expect(_testValueProvider.allButArray).to.be.a('function');39 expect(_testValueProvider.allButFunction).to.be.a('function');40 expect(_testValueProvider.allButBoolean).to.be.a('function');41 });42 describe('allButSelected()', () => {43 it('should return an array of all test values when invoked without arguments', () => {44 const values = _testValueProvider.allButSelected();45 const expectedValues = _getExpectedValues();46 _checkResults(values, expectedValues);47 });48 it('should omit undefined values if one of the arguments is "undefined"', () => {49 const values = _testValueProvider.allButSelected('undefined');50 const expectedValues = _getExpectedValues();51 expectedValues.primitives.splice(0, 1);52 _checkResults(values, expectedValues);53 });54 it('should omit null values if one of the arguments is "null"', () => {55 const values = _testValueProvider.allButSelected('null');56 const expectedValues = _getExpectedValues();57 expectedValues.primitives.splice(1, 1);58 _checkResults(values, expectedValues);59 });60 it('should omit null values if one of the arguments is "number"', () => {61 const values = _testValueProvider.allButSelected('number');62 const expectedValues = _getExpectedValues();63 expectedValues.primitives.splice(2, 1);64 _checkResults(values, expectedValues);65 });66 it('should omit null values if one of the arguments is "string"', () => {67 const values = _testValueProvider.allButSelected('string');68 const expectedValues = _getExpectedValues();69 expectedValues.primitives.splice(3, 1);70 _checkResults(values, expectedValues);71 });72 it('should omit null values if one of the arguments is "boolean"', () => {73 const values = _testValueProvider.allButSelected('boolean');74 const expectedValues = _getExpectedValues();75 expectedValues.primitives.splice(4, 1);76 _checkResults(values, expectedValues);77 });78 it('should omit object values if one of the arguments is "object"', () => {79 const values = _testValueProvider.allButSelected('object');80 const expectedValues = _getExpectedValues();81 expectedValues.complex.splice(0, 1);82 _checkResults(values, expectedValues);83 });84 it('should omit array values if one of the arguments is "array"', () => {85 const values = _testValueProvider.allButSelected('array');86 const expectedValues = _getExpectedValues();87 expectedValues.complex.splice(1, 1);88 _checkResults(values, expectedValues);89 });90 it('should omit function values if one of the arguments is "function"', () => {91 const values = _testValueProvider.allButSelected('function');92 const expectedValues = _getExpectedValues();93 expectedValues.complex.splice(2, 1);94 _checkResults(values, expectedValues);95 });96 it('should omit multiple arguments when multiple args are specified', () => {97 const values = _testValueProvider.allButSelected('function', 'string');98 const expectedValues = _getExpectedValues();99 expectedValues.primitives.splice(3, 1);100 expectedValues.complex.splice(2, 1);101 _checkResults(values, expectedValues);102 });103 });104 describe('allButUndefined()', () => {105 it('should return an array with expected values when invoked', () => {106 const values = _testValueProvider.allButUndefined();107 const expectedValues = _getExpectedValues();108 expectedValues.primitives.splice(0, 1);109 _checkResults(values, expectedValues);110 });111 it('should append the specified arguments to the return array', () => {112 const appendedValues = ['foo', -1, '', false];113 const values = _testValueProvider.allButUndefined.apply(_testValueProvider, appendedValues);114 const expectedValues = _getExpectedValues();115 expectedValues.primitives.splice(0, 1);116 expectedValues.extra = appendedValues;117 _checkResults(values, expectedValues);118 });119 });120 describe('allButNull()', () => {121 it('should return an array with expected values when invoked', () => {122 const values = _testValueProvider.allButNull();123 const expectedValues = _getExpectedValues();124 expectedValues.primitives.splice(1, 1);125 _checkResults(values, expectedValues);126 });127 it('should append the specified arguments to the return array', () => {128 const appendedValues = ['foo', -1, '', false];129 const values = _testValueProvider.allButNull.apply(_testValueProvider, appendedValues);130 const expectedValues = _getExpectedValues();131 expectedValues.primitives.splice(1, 1);132 expectedValues.extra = appendedValues;133 _checkResults(values, expectedValues);134 });135 });136 describe('allButNumber()', () => {137 it('should return an array with expected values when invoked', () => {138 const values = _testValueProvider.allButNumber();139 const expectedValues = _getExpectedValues();140 expectedValues.primitives.splice(2, 1);141 _checkResults(values, expectedValues);142 });143 it('should append the specified arguments to the return array', () => {144 const appendedValues = ['foo', -1, '', false];145 const values = _testValueProvider.allButNumber.apply(_testValueProvider, appendedValues);146 const expectedValues = _getExpectedValues();147 expectedValues.primitives.splice(2, 1);148 expectedValues.extra = appendedValues;149 _checkResults(values, expectedValues);150 });151 });152 describe('allButString()', () => {153 it('should return an array with expected values when invoked', () => {154 const values = _testValueProvider.allButString();155 const expectedValues = _getExpectedValues();156 expectedValues.primitives.splice(3, 1);157 _checkResults(values, expectedValues);158 });159 it('should append the specified arguments to the return array', () => {160 const appendedValues = ['foo', -1, '', false];161 const values = _testValueProvider.allButString.apply(_testValueProvider, appendedValues);162 const expectedValues = _getExpectedValues();163 expectedValues.primitives.splice(3, 1);164 expectedValues.extra = appendedValues;165 _checkResults(values, expectedValues);166 });167 });168 describe('allButObject()', () => {169 it('should return an array with expected values when invoked', () => {170 const values = _testValueProvider.allButObject();171 const expectedValues = _getExpectedValues();172 expectedValues.complex.splice(0, 1);173 _checkResults(values, expectedValues);174 });175 it('should append the specified arguments to the return array', () => {176 const appendedValues = ['foo', -1, '', false];177 const values = _testValueProvider.allButObject.apply(_testValueProvider, appendedValues);178 const expectedValues = _getExpectedValues();179 expectedValues.complex.splice(0, 1);180 expectedValues.extra = appendedValues;181 _checkResults(values, expectedValues);182 });183 });184 describe('allButArray()', () => {185 it('should return an array with expected values when invoked', () => {186 const values = _testValueProvider.allButArray();187 const expectedValues = _getExpectedValues();188 expectedValues.complex.splice(1, 1);189 _checkResults(values, expectedValues);190 });191 it('should append the specified arguments to the return array', () => {192 const appendedValues = ['foo', -1, '', false];193 const values = _testValueProvider.allButArray.apply(_testValueProvider, appendedValues);194 const expectedValues = _getExpectedValues();195 expectedValues.complex.splice(1, 1);196 expectedValues.extra = appendedValues;197 _checkResults(values, expectedValues);198 });199 });200 describe('allButFunction()', () => {201 it('should return an array with expected values when invoked', () => {202 const values = _testValueProvider.allButFunction();203 const expectedValues = _getExpectedValues();204 expectedValues.complex.splice(2, 1);205 _checkResults(values, expectedValues);206 });207 it('should append the specified arguments to the return array', () => {208 const appendedValues = ['foo', -1, '', false];209 const values = _testValueProvider.allButFunction.apply(_testValueProvider, appendedValues);210 const expectedValues = _getExpectedValues();211 expectedValues.complex.splice(2, 1);212 expectedValues.extra = appendedValues;213 _checkResults(values, expectedValues);214 });215 });216 describe('allButBoolean()', () => {217 it('should return an array with expected values when invoked', () => {218 const values = _testValueProvider.allButBoolean();219 const expectedValues = _getExpectedValues();220 expectedValues.primitives.splice(4, 1);221 _checkResults(values, expectedValues);222 });223 it('should append the specified arguments to the return array', () => {224 const appendedValues = ['foo', -1, '', false];225 const values = _testValueProvider.allButBoolean.apply(_testValueProvider, appendedValues);226 const expectedValues = _getExpectedValues();227 expectedValues.primitives.splice(4, 1);228 expectedValues.extra = appendedValues;229 _checkResults(values, expectedValues);230 });231 });...

Full Screen

Full Screen

analysisRepositorySpec.js

Source:analysisRepositorySpec.js Github

copy

Full Screen

1'use strict';2var proxyquire = require('proxyquire');3var sinon = require('sinon');4var chai = require('chai');5var expect = chai.expect;6var queryStub = {7 query: function() {8 console.log('query being called');9 }10},11 dbStub = function() {12 return queryStub;13 };14var analysisRepository = proxyquire('../standalone-app/analysisRepository', {15 './db': dbStub16});17describe('the analysis repository', function() {18 var expectedError = 'error';19 var analysisId = 1;20 var ownerAccountId = 1;21 function succesCallback(query, expectedQuery, expectedValues, expectedResult, done) {22 return function(error, result) {23 sinon.assert.calledWith(query, expectedQuery, expectedValues);24 expect(error).to.be.null;25 expect(result).to.deep.equal(expectedResult);26 done();27 };28 }29 function succesCallbackWithoutReturnValue(query, expectedQuery, expectedValues, done) {30 return function(error) {31 sinon.assert.calledWith(query, expectedQuery, expectedValues);32 expect(error).to.be.undefined;33 done();34 };35 }36 function errorCallback(query, expectedQuery, expectedValues, done) {37 return function(error) {38 sinon.assert.calledWith(query, expectedQuery, expectedValues);39 expect(error).to.equal(expectedError);40 done();41 };42 }43 describe('get', function() {44 var query;45 var expectedQuery = 'SELECT * FROM analysis WHERE ID=$1';46 beforeEach(function() {47 query = sinon.stub(queryStub, 'query');48 });49 afterEach(function() {50 query.restore();51 });52 it('should get the analysis and call the callback with the result', function(done) {53 var queryResult = {54 rows: [{ primarymodel: {} }]55 };56 var expectedResult = {57 primaryModel: {}58 };59 query.onCall(0).yields(null, queryResult);60 var expectedValues = [analysisId];61 var callback = succesCallback(query, expectedQuery, expectedValues, expectedResult, done);62 analysisRepository.get(analysisId, callback);63 });64 it('should call callback with only an error', function(done) {65 query.onCall(0).yields(expectedError);66 var expectedValues = [analysisId];67 var callback = errorCallback(query, expectedQuery, expectedValues, done);68 analysisRepository.get(analysisId, callback);69 });70 });71 describe('query', function() {72 var query;73 var expectedQuery = 'SELECT id, owner, title, problem, outcome FROM analysis WHERE OWNER=$1';74 beforeEach(function() {75 query = sinon.stub(queryStub, 'query');76 });77 afterEach(function() {78 query.restore();79 });80 it('should get all analyses for an owner and call the callback withg the result', function(done) {81 var queryResult = {82 rows: [{ primarymodel: {} }]83 };84 query.onCall(0).yields(null, queryResult);85 var expectedValues = [ownerAccountId];86 var callback = succesCallback(query, expectedQuery, expectedValues, queryResult, done);87 analysisRepository.query(ownerAccountId, callback);88 });89 it('should call callback with only an error', function(done) {90 query.onCall(0).yields(expectedError);91 var expectedValues = [ownerAccountId];92 var callback = errorCallback(query, expectedQuery, expectedValues, done);93 analysisRepository.query(ownerAccountId, callback);94 });95 });96 describe('create', function() {97 var query;98 var expectedQuery = 'INSERT INTO analysis (title, outcome, problem, owner) VALUES($1, $2, $3, $4) RETURNING id';99 var newAnalysis = {100 title: 'title',101 outcome: 'outcome',102 problem: 'problem'103 };104 beforeEach(function() {105 query = sinon.stub(queryStub, 'query');106 });107 afterEach(function() {108 query.restore();109 });110 it('should insert new analysis and call callback with the id of the new analysis', function(done) {111 var queryResult = {112 rows: [{113 id: 1114 }]115 };116 var expectedResult = 1;117 query.onCall(0).yields(null, queryResult);118 var expectedValues = [newAnalysis.title, newAnalysis.outcome, newAnalysis.problem, ownerAccountId];119 var callback = succesCallback(query, expectedQuery, expectedValues, expectedResult, done);120 analysisRepository.create(ownerAccountId, newAnalysis, callback);121 });122 it('should call callback with only an error', function(done) {123 query.onCall(0).yields(expectedError);124 var expectedValues = [newAnalysis.title, newAnalysis.outcome, newAnalysis.problem, ownerAccountId];125 var callback = errorCallback(query, expectedQuery, expectedValues, done);126 analysisRepository.create(ownerAccountId, newAnalysis, callback);127 });128 });129 describe('setPrimaryModel', function() {130 var query;131 var primaryModelId = 1;132 var expectedQuery = 'UPDATE analysis SET primaryModel = $1 where id = $2';133 beforeEach(function() {134 query = sinon.stub(queryStub, 'query');135 });136 afterEach(function() {137 query.restore();138 });139 it('should update the primary model of the analysis', function(done) {140 query.onCall(0).yields(null);141 var expectedValues = [primaryModelId, analysisId];142 var callback = succesCallbackWithoutReturnValue(query, expectedQuery, expectedValues, done);143 analysisRepository.setPrimaryModel(analysisId, primaryModelId, callback);144 });145 it('should call callback with only an error', function(done) {146 query.onCall(0).yields(expectedError);147 var expectedValues = [primaryModelId, analysisId];148 var callback = errorCallback(query, expectedQuery, expectedValues, done);149 analysisRepository.setPrimaryModel(analysisId, primaryModelId, callback);150 });151 });152 describe('setTitle', function() {153 var query;154 var expectedQuery = 'UPDATE analysis SET title = $1 WHERE id = $2';155 beforeEach(function() {156 query = sinon.stub(queryStub, 'query');157 });158 afterEach(function() {159 query.restore();160 });161 var newTitle = 'title';162 it('should update the title of the analysis', function(done) {163 query.onCall(0).yields(null);164 var expectedValues = [newTitle, analysisId];165 var callback = succesCallbackWithoutReturnValue(query, expectedQuery, expectedValues, done);166 analysisRepository.setTitle(analysisId, newTitle, callback);167 });168 it('should call callback with only an error', function(done) {169 query.onCall(0).yields(expectedError);170 var expectedValues = [newTitle, analysisId];171 var callback = errorCallback(query, expectedQuery, expectedValues, done);172 analysisRepository.setTitle(analysisId, newTitle, callback);173 });174 });175 describe('setOutcome', function() {176 var query;177 var expectedQuery = 'UPDATE analysis SET outcome = $1 WHERE id = $2';178 beforeEach(function() {179 query = sinon.stub(queryStub, 'query');180 });181 afterEach(function() {182 query.restore();183 });184 var newOutcome = '{name: "newName", direction:-1}';185 it('should update the outcome of the analysis', function(done) {186 query.onCall(0).yields(null);187 var expectedValues = [newOutcome, analysisId];188 var callback = succesCallbackWithoutReturnValue(query, expectedQuery, expectedValues, done);189 analysisRepository.setOutcome(analysisId, newOutcome, callback);190 });191 it('should call callback with only an error', function(done) {192 query.onCall(0).yields(expectedError);193 var expectedValues = [newOutcome, analysisId];194 var callback = errorCallback(query, expectedQuery, expectedValues, done);195 analysisRepository.setOutcome(analysisId, newOutcome, callback);196 });197 });198 describe('deleteAnalysis', function() {199 var query;200 var expectedQuery = 'DELETE FROM analysis WHERE id = $1';201 beforeEach(function() {202 query = sinon.stub(queryStub, 'query');203 });204 afterEach(function() {205 query.restore();206 });207 it('should delete the analysis from the table', function(done) {208 query.onCall(0).yields(null);209 var expectedValues = [analysisId];210 var callback = succesCallbackWithoutReturnValue(query, expectedQuery, expectedValues, done);211 analysisRepository.deleteAnalysis(analysisId, callback);212 });213 it('should call the callback with only an error', function(done) {214 query.onCall(0).yields(expectedError);215 var expectedValues = [analysisId];216 var callback = errorCallback(query, expectedQuery, expectedValues, done);217 analysisRepository.deleteAnalysis(analysisId, callback);218 });219 });220 describe('setProblem', function() {221 var query;222 var expectedQuery = 'UPDATE analysis SET problem = $1 WHERE id = $2';223 var problem = {};224 beforeEach(function() {225 query = sinon.stub(queryStub, 'query');226 });227 afterEach(function() {228 query.restore();229 });230 it('should update the problem in the analysis table', function(done) {231 query.onCall(0).yields(null);232 var expectedValues = [problem, analysisId];233 var callback = succesCallbackWithoutReturnValue(query, expectedQuery, expectedValues, done);234 analysisRepository.setProblem(analysisId, problem, callback);235 });236 it('should call the callback with only an error', function(done) {237 query.onCall(0).yields(expectedError);238 var expectedValues = [problem, analysisId];239 var callback = errorCallback(query, expectedQuery, expectedValues, done);240 analysisRepository.setProblem(analysisId, problem, callback);241 });242 });...

Full Screen

Full Screen

data.js

Source:data.js Github

copy

Full Screen

1/**2 * @typedef {Object} DoorItem3 * @property {string} label4 * @property {{ nRed: number, nBlack: number }} expectedValues5*/6/** @type {Array<DoorItem>} */7export default [8 {9 label: '1',10 expectedValues: {11 nRed: 0,12 nBlack: 013 }14 },15 {16 label: '2',17 expectedValues: {18 nRed: 0,19 nBlack: 020 }21 },22 {23 label: '3',24 expectedValues: {25 nRed: 0,26 nBlack: 027 }28 },29 {30 label: '4',31 expectedValues: {32 nRed: 0,33 nBlack: 034 }35 },36 {37 label: '5',38 expectedValues: {39 nRed: 0,40 nBlack: 041 }42 },43 {44 label: '6',45 expectedValues: {46 nRed: 0,47 nBlack: 048 }49 },50 {51 label: '7',52 expectedValues: {53 nRed: 0,54 nBlack: 055 }56 },57 {58 label: '8',59 expectedValues: {60 nRed: 11,61 nBlack: 862 }63 },64 {65 label: '9',66 expectedValues: {67 nRed: 0,68 nBlack: 069 }70 },71 {72 label: '10',73 expectedValues: {74 nRed: 0,75 nBlack: 076 }77 },78 {79 label: '11',80 expectedValues: {81 nRed: 0,82 nBlack: 083 }84 },85 {86 label: '12',87 expectedValues: {88 nRed: 0,89 nBlack: 090 }91 },92 {93 label: '13',94 expectedValues: {95 nRed: 0,96 nBlack: 097 }98 },99 {100 label: '14',101 expectedValues: {102 nRed: 0,103 nBlack: 0104 }105 },106 {107 label: '15',108 expectedValues: {109 nRed: 0,110 nBlack: 0111 }112 },113 {114 label: '16',115 expectedValues: {116 nRed: 0,117 nBlack: 0118 }119 },120 {121 label: '17',122 expectedValues: {123 nRed: 0,124 nBlack: 0125 }126 },127 {128 label: '18',129 expectedValues: {130 nRed: 0,131 nBlack: 0132 }133 },134 {135 label: '19',136 expectedValues: {137 nRed: 0,138 nBlack: 0139 }140 },141 {142 label: '20',143 expectedValues: {144 nRed: 0,145 nBlack: 0146 }147 },148 {149 label: '21',150 expectedValues: {151 nRed: 0,152 nBlack: 0153 }154 },155 {156 label: '22',157 expectedValues: {158 nRed: 0,159 nBlack: 0160 }161 },162 {163 label: '23',164 expectedValues: {165 nRed: 0,166 nBlack: 0167 }168 },169 {170 label: '24',171 expectedValues: {172 nRed: 0,173 nBlack: 0174 }175 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2const { expectedValues } = require("fast-check-monorepo");3 .array(fc.integer(), 1, 10)4 .chain(arr => fc.tuple(fc.constant(arr), fc.constant(arr.length)));5expectedValues(myArbitrary, 10, { verbose: true });6{7 "scripts": {8 },9 "dependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const {expectedValues} = require('fast-check');2const obj = {3};4const expectedKeys = ['a', 'b', 'c'];5test('should pass', () => {6 expect(expectedValues(obj, expectedKeys)).toEqual([1, 2, 3]);7});8test('should fail', () => {9 expect(expectedValues(obj, expectedKeys)).toEqual([1, 3, 2]);10});11test('should pass', () => {12 expect(expectedValues(obj, expectedKeys)).toEqual([3, 2, 1]);13});14test('should fail', () => {15 expect(expectedValues(obj, expectedKeys)).toEqual([2, 1, 3]);16});17test('should pass', () => {18 expect(expectedValues(obj, expectedKeys)).toEqual([2, 3, 1]);19});20test('should fail', () => {21 expect(expectedValues(obj, expectedKeys)).toEqual([3, 1, 2]);22});23test('should pass', () => {24 expect(expectedValues(obj, expectedKeys)).toEqual([3, 1]);25});26test('should fail', () => {27 expect(expectedValues(obj, expectedKeys)).toEqual([1, 3]);28});29test('should pass', () => {30 expect(expectedValues(obj, expectedKeys)).toEqual([1, 3, 2, 4]);31});32test('should fail', () => {33 expect(expectedValues(obj, expectedKeys)).toEqual([1, 2, 3, 4]);34});35test('should pass', () => {36 expect(expectedValues(obj, expectedKeys)).toEqual([1, 2, 3, 4, 5]);37});38test('should fail', () => {39 expect(expectedValues(obj, expectedKeys)).toEqual([1, 2, 3]);40});41test('should pass', () => {42 expect(expectedValues(obj, expectedKeys)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const expectedValues = require('fast-check-monorepo').expectedValues;3const myArbitrary = fc.integer(1, 10);4const myTest = () => {5 const values = expectedValues(myArbitrary);6 console.log(values);7};8myTest();

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { expectedValues } = require('fast-check-monorepo');3const { getExpectedValues } = expectedValues();4const myArbitrary = fc.constantFrom('a', 'b', 'c');5const myExpectedValues = getExpectedValues(myArbitrary);6console.log(myExpectedValues);7const fc = require('fast-check');8const { expectedValues } = require('fast-check');9const { getExpectedValues } = expectedValues();10const myArbitrary = fc.constantFrom('a', 'b', 'c');11const myExpectedValues = getExpectedValues(myArbitrary);12console.log(myExpectedValues);13const fc = require('fast-check');14const { getExpectedValues } = require('fast-check');15const myArbitrary = fc.constantFrom('a', 'b', 'c');16const myExpectedValues = getExpectedValues(myArbitrary);17console.log(myExpectedValues);18if the arbitrary is a constant or a constantFrom , then the expected values are the list of all the possible values of the arbitrary;19if the arbitrary is a boolean , then the expected values are the list of all the possible values of the arbitrary;20if the arbitrary is a tuple , then the expected values are the cartesian product of the expected values of all the arbitraries of the tuple;21if the arbitrary is a record , then the expected values are the cartesian product of the expected values of all the arbitraries of the record;22if the arbitrary is a oneof , then the expected values are the union of the expected values of all the arbitraries of the oneof;23if the arbitrary is a frequency , then the expected values are the union of the expected values of all the arbitraries of the frequency;24if the arbitrary is a set , then the expected values are the list of all the possible subsets of the expected values of the set;25if the arbitrary is a map , then the expected values are the list of all the possible maps of the expected values of the map;26if the arbitrary is a bigInt , then the expected values are the list of all the possible values of the arbitrary;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { check, property } = require('fast-check');2const expectedValues = require('fast-check-monorepo').expectedValues;3check(property(expectedValues(), (x) => x > 0));4{5 "compilerOptions": {6 "paths": {7 }8 },9}105 check(property(expectedValues(), (x) => x > 0));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { check } = require('fast-check');2const { runDetails } = require('fast-check');3const expectedValues = runDetails.expectedValues;4const checkProp = check(5 check => check.integer({ min: 0, max: 100 }),6 (i) => {7 if (i < 50) {8 throw new Error('i is less than 50');9 }10 return true;11 }12);13checkProp.then((result) => {14 console.log(expectedValues(result));15});16{ failedRuns: 1, numRuns: 1, seed: 1 }

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful