Best JavaScript code snippet using ava
controllers.js
Source:controllers.js
...7 describe("create", () => {8 const controllerCreate = require("../../controllers/products/create");9 const response = {};10 const request = {};11 let next = sinon.stub().returns((c) => {});12 describe("erro", () => {13 before(() => {14 request.body = {};15 response.status = sinon.stub().returns(response);16 response.json = sinon.stub().returns();17 });18 after(() => {19 sinon.restore();20 });21 it("sem body chama next", async () => {22 await controllerCreate(request, response, next);23 expect(24 next.calledWith({25 message: "must inform name, qty",26 code: "invalid_data",27 })28 );29 });30 });31 describe("service retorna erro", () => {32 before(() => {33 request.body = { name: "khkj jsh df", quantity: 9 };34 response.status = sinon.stub().returns(response);35 response.json = sinon.stub().returns();36 sinon37 .stub(serviceProduct, "create")38 .resolves({ err: { message: "", code: "" } });39 });40 after(() => {41 sinon.restore();42 });43 it("sem body chama next", async () => {44 await controllerCreate(request, response, next);45 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(46 true47 );48 });49 });50 describe("service retorna ok", () => {51 before(() => {52 request.body = { name: "khkj jsh df", quantity: 9 };53 response.status = sinon.stub().returns(response);54 response.json = sinon.stub().returns();55 sinon56 .stub(serviceProduct, "create")57 .resolves({ name: "khkj jsh df", quantity: 9 });58 });59 after(() => {60 sinon.restore();61 });62 it("chama res", async () => {63 await controllerCreate(request, response, next);64 expect(response.status.calledWith(201)).to.be.equal(true);65 });66 });67 });68 describe("delete", () => {69 const controllerDelete = require("../../controllers/products/delete");70 let next = sinon.stub().returns((c) => {});71 describe("deletar produto erro", () => {72 before(() => {73 request.params = {};74 response.status = sinon.stub().returns(response);75 response.json = sinon.stub().returns();76 sinon.stub(serviceProduct, "remove").resolves({77 err: { message: "Wrong id format", code: "invalid_data" },78 });79 });80 after(() => {81 sinon.restore();82 });83 it("chama next", async () => {84 await controllerDelete(request, response, next);85 expect(86 next.calledOnceWith({87 err: { message: "Wrong id format", code: "invalid_data" },88 })89 ).to.be.equal(true);90 });91 });92 describe("deletar produto ok", () => {93 before(() => {94 request.params = { id: "thisisarealid" };95 response.status = sinon.stub().returns(response);96 response.json = sinon.stub().returns();97 sinon.stub(serviceProduct, "remove").resolves({98 name: "product name",99 quantity: 8,100 });101 });102 after(() => {103 sinon.restore();104 });105 it("retorna status 200", async () => {106 await controllerDelete(request, response, next);107 expect(response.status.calledOnceWith(200)).to.be.equal(true);108 });109 });110 });111 describe("get", () => {112 const controllerGet = require("../../controllers/products/get");113 let next = sinon.stub().returns((c) => {});114 describe("buscar produto erro", () => {115 before(() => {116 request.params = {};117 response.status = sinon.stub().returns(response);118 response.json = sinon.stub().returns();119 sinon.stub(serviceProduct, "remove").resolves({120 err: { message: "Wrong id format", code: "invalid_data" },121 });122 });123 after(() => {124 sinon.restore();125 });126 it("chama next", async () => {127 await controllerGet(request, response, next);128 expect(129 next.calledOnceWith({130 err: { message: "Wrong id format", code: "invalid_data" },131 })132 ).to.be.equal(true);133 });134 });135 describe("buscar produto ok", () => {136 before(() => {137 request.params = { id: "thisisarealid" };138 response.status = sinon.stub().returns(response);139 response.json = sinon.stub().returns();140 sinon.stub(serviceProduct, "get").resolves({141 name: "product name",142 quantity: 8,143 });144 });145 after(() => {146 sinon.restore();147 });148 it("retorna status 200", async () => {149 await controllerGet(request, response, next);150 expect(response.status.calledOnceWith(200)).to.be.equal(true);151 });152 });153 });154 describe("list", () => {155 const controllerList = require("../../controllers/products/list");156 let next = sinon.stub().returns((c) => {});157 describe("buscar produto ok", () => {158 before(() => {159 response.status = sinon.stub().returns(response);160 response.json = sinon.stub().returns();161 sinon.stub(serviceProduct, "list").resolves([162 {163 name: "product name",164 quantity: 8,165 },166 ]);167 });168 after(() => {169 sinon.restore();170 });171 it("retorna status 200", async () => {172 await controllerList(request, response, next);173 expect(response.status.calledOnceWith(200)).to.be.equal(true);174 });175 });176 });177 describe("update", () => {178 const controllerUpdate = require("../../controllers/products/update");179 const response = {};180 const request = {};181 let next = sinon.stub().returns((c) => {});182 describe("erro", () => {183 before(() => {184 request.body = {};185 request.params = {};186 response.status = sinon.stub().returns(response);187 response.json = sinon.stub().returns();188 });189 after(() => {190 sinon.restore();191 });192 it("sem body chama next", async () => {193 await controllerUpdate(request, response, next);194 expect(195 next.calledWith({196 message: "must inform name, qty",197 code: "invalid_data",198 })199 );200 });201 });202 describe("service retorna erro", () => {203 before(() => {204 request.body = { name: "khkj jsh df", quantity: 9 };205 response.status = sinon.stub().returns(response);206 response.json = sinon.stub().returns();207 sinon208 .stub(serviceProduct, "update")209 .resolves({ err: { message: "", code: "" } });210 });211 after(() => {212 sinon.restore();213 });214 it("sem body chama next", async () => {215 await controllerUpdate(request, response, next);216 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(217 true218 );219 });220 });221 describe("service retorna ok", () => {222 before(() => {223 request.body = { name: "khkj jsh df", quantity: 9 };224 response.status = sinon.stub().returns(response);225 response.json = sinon.stub().returns();226 sinon227 .stub(serviceProduct, "update")228 .resolves({ name: "khkj jsh df", quantity: 9 });229 });230 after(() => {231 sinon.restore();232 });233 it("chama res", async () => {234 await controllerUpdate(request, response, next);235 expect(response.status.calledWith(200)).to.be.equal(true);236 });237 });238 });239});240describe("controller sales", () => {241 describe("create", () => {242 const controllerCreate = require("../../controllers/sales/create");243 const response = {};244 const request = {};245 let next = sinon.stub().returns((c) => {});246 describe("erro", () => {247 before(() => {248 request.body = undefined;249 response.status = sinon.stub().returns(response);250 response.json = sinon.stub().returns();251 });252 after(() => {253 sinon.restore();254 });255 it("sem body chama next", async () => {256 await controllerCreate(request, response, next);257 expect(258 next.calledWith({259 message: "Wrong product ID or invalid quantity",260 code: "invalid_data",261 })262 );263 });264 });265 describe("service retorna erro", () => {266 before(() => {267 request.body = { name: "khkj jsh df", quantity: 9 };268 response.status = sinon.stub().returns(response);269 response.json = sinon.stub().returns();270 sinon271 .stub(serviceSales, "create")272 .resolves({ err: { message: "", code: "" } });273 });274 after(() => {275 sinon.restore();276 });277 it("sem body chama next", async () => {278 await controllerCreate(request, response, next);279 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(280 true281 );282 });283 });284 describe("service retorna ok", () => {285 before(() => {286 request.body = { name: "khkj jsh df", quantity: 9 };287 response.status = sinon.stub().returns(response);288 response.json = sinon.stub().returns();289 sinon290 .stub(serviceSales, "create")291 .resolves({ name: "khkj jsh df", quantity: 9 });292 });293 after(() => {294 sinon.restore();295 });296 it("chama res", async () => {297 await controllerCreate(request, response, next);298 expect(response.status.calledWith(200)).to.be.equal(true);299 });300 });301 });302 describe("delete", () => {303 const controllerDelete = require("../../controllers/sales/delete");304 let next = sinon.stub().returns((c) => {});305 describe("deletar sale erro", () => {306 before(() => {307 request.params = {};308 response.status = sinon.stub().returns(response);309 response.json = sinon.stub().returns();310 sinon.stub(serviceSales, "remove").resolves({311 err: { message: "Wrong id format", code: "invalid_data" },312 });313 });314 after(() => {315 sinon.restore();316 });317 it("chama next", async () => {318 await controllerDelete(request, response, next);319 expect(320 next.calledOnceWith({321 err: { message: "Wrong id format", code: "invalid_data" },322 })323 ).to.be.equal(true);324 });325 });326 describe("deletar sale ok", () => {327 before(() => {328 request.params = { id: "thisisarealid" };329 response.status = sinon.stub().returns(response);330 response.json = sinon.stub().returns();331 sinon.stub(serviceSales, "remove").resolves({332 name: "product name",333 quantity: 8,334 });335 });336 after(() => {337 sinon.restore();338 });339 it("retorna status 200", async () => {340 await controllerDelete(request, response, next);341 expect(response.status.calledOnceWith(200)).to.be.equal(true);342 });343 });344 });345 describe("get", () => {346 const controllerGet = require("../../controllers/sales/get");347 let next = sinon.stub().returns((c) => {});348 describe("buscar produto sem id", () => {349 const response = {};350 const request = {};351 before(() => {352 request.params = {};353 response.status = sinon.stub().returns(response);354 response.json = sinon.stub().returns();355 });356 after(() => {357 sinon.restore();358 });359 it("chama next", async () => {360 await controllerGet(request, response, next);361 expect(362 next.calledOnceWith({363 err: { status: 404, code: "not_found" },364 })365 ).to.be.equal(true);366 });367 });368 describe("buscar produto erro", () => {369 before(() => {370 request.params = { id: "123" };371 response.status = sinon.stub().returns(response);372 response.json = sinon.stub().returns();373 sinon.stub(serviceSales, "get").resolves({374 err: { message: "Wrong id format", code: "invalid_data" },375 });376 });377 after(() => {378 sinon.restore();379 });380 it("chama next", async () => {381 await controllerGet(request, response, next);382 expect(383 next.calledOnceWith({384 err: { message: "Wrong id format", code: "invalid_data" },385 })386 ).to.be.equal(true);387 });388 });389 describe("buscar produto ok", () => {390 before(() => {391 request.params = { id: "thisisarealid" };392 response.status = sinon.stub().returns(response);393 response.json = sinon.stub().returns();394 sinon.stub(serviceProduct, "get").resolves({395 name: "product name",396 quantity: 8,397 });398 });399 after(() => {400 sinon.restore();401 });402 it("retorna status 200", async () => {403 await controllerGet(request, response, next);404 expect(response.status.calledOnceWith(200)).to.be.equal(true);405 });406 });407 });408 describe("list", () => {409 const controllerList = require("../../controllers/products/list");410 let next = sinon.stub().returns((c) => {});411 describe("buscar produto ok", () => {412 before(() => {413 response.status = sinon.stub().returns(response);414 response.json = sinon.stub().returns();415 sinon.stub(serviceProduct, "list").resolves([416 {417 name: "product name",418 quantity: 8,419 },420 ]);421 });422 after(() => {423 sinon.restore();424 });425 it("retorna status 200", async () => {426 await controllerList(request, response, next);427 expect(response.status.calledOnceWith(200)).to.be.equal(true);428 });429 });430 });431 describe("update", () => {432 const controllerUpdate = require("../../controllers/products/update");433 const response = {};434 const request = {};435 let next = sinon.stub().returns((c) => {});436 describe("erro", () => {437 before(() => {438 request.body = {};439 request.params = {};440 response.status = sinon.stub().returns(response);441 response.json = sinon.stub().returns();442 });443 after(() => {444 sinon.restore();445 });446 it("sem body chama next", async () => {447 await controllerUpdate(request, response, next);448 expect(449 next.calledWith({450 message: "must inform name, qty",451 code: "invalid_data",452 })453 );454 });455 });456 describe("service retorna erro", () => {457 before(() => {458 request.body = { name: "khkj jsh df", quantity: 9 };459 response.status = sinon.stub().returns(response);460 response.json = sinon.stub().returns();461 sinon462 .stub(serviceProduct, "update")463 .resolves({ err: { message: "", code: "" } });464 });465 after(() => {466 sinon.restore();467 });468 it("sem body chama next", async () => {469 await controllerUpdate(request, response, next);470 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(471 true472 );473 });474 });475 describe("service retorna ok", () => {476 before(() => {477 request.body = { name: "khkj jsh df", quantity: 9 };478 response.status = sinon.stub().returns(response);479 response.json = sinon.stub().returns();480 sinon481 .stub(serviceProduct, "update")482 .resolves({ name: "khkj jsh df", quantity: 9 });483 });484 after(() => {485 sinon.restore();486 });487 it("chama res", async () => {488 await controllerUpdate(request, response, next);489 expect(response.status.calledWith(200)).to.be.equal(true);490 });491 });492 });493});
utils.js
Source:utils.js
...28 erizoController: {report: {}}29 });30 module.exports.spawn = {31 stdout: {32 setEncoding: sinon.stub(),33 on: sinon.stub()34 },35 stderr: {36 setEncoding: sinon.stub(),37 on: sinon.stub()38 },39 on: sinon.stub(),40 unref: sinon.stub(),41 kill: sinon.stub()42 };43 module.exports.childProcess = createMock('child_process', {44 spawn: sinon.stub().returns(module.exports.spawn)45 });46 module.exports.ec2Client = {47 call: sinon.stub()48 };49 module.exports.awslib = createMock('aws-lib', {50 createEC2Client: sinon.stub().returns(module.exports.ec2Client)51 });52 module.exports.os = createMock('os', {53 networkInterfaces: sinon.stub()54 });55 module.exports.fs = createMock('fs', {56 openSync: sinon.stub(),57 close: sinon.stub()58 });59 module.exports.Server = {60 listen: sinon.stub()61 };62 module.exports.signature = {63 update: sinon.stub(),64 digest: sinon.stub()65 };66 module.exports.crypto = createMock('crypto', {67 createHmac: sinon.stub().returns(module.exports.signature),68 randomBytes: sinon.stub().returns(new Buffer(16))69 });70 module.exports.http = createMock('http', {71 createServer: sinon.stub().returns(module.exports.Server),72 close: sinon.stub()73 });74 module.exports.socketInstance = {75 conn: {transport: {socket: {internalOnClose: undefined}}},76 disconnect: sinon.stub(),77 emit: sinon.stub(),78 on: sinon.stub()79 };80 module.exports.socketIoInstance = {81 set: sinon.stub(),82 sockets: {83 on: sinon.stub(),84 socket: sinon.stub().returns(module.exports.socketInstance), // v0.985 sockets:{'streamId1': module.exports.socketInstance, // v2.0.386 undefined: module.exports.socketInstance},87 indexOf: sinon.stub()88 }89 };90 module.exports.socketIo = createMock('socket.io', {91 listen: sinon.stub().returns(module.exports.socketIoInstance),92 close: sinon.stub()93 });94 module.exports.amqper = createMock('../common/amqper', {95 connect: sinon.stub().callsArg(0),96 broadcast: sinon.stub(),97 setPublicRPC: sinon.stub(),98 callRpc: sinon.stub(),99 bind: sinon.stub(),100 bindBroadcast: sinon.stub()101 });102 module.exports.ErizoAgentReporterInstance = {103 getErizoAgent: sinon.stub()104 };105 module.exports.erizoAgentReporter = createMock('../erizoAgent/erizoAgentReporter', {106 Reporter: sinon.stub().returns(module.exports.ErizoAgentReporterInstance)107 });108 module.exports.OneToManyProcessor = {109 addExternalOutput: sinon.stub(),110 setExternalPublisher: sinon.stub(),111 setPublisher: sinon.stub(),112 addSubscriber: sinon.stub(),113 removeSubscriber: sinon.stub(),114 close: sinon.stub(),115 };116 module.exports.ConnectionDescription = {117 close: sinon.stub(),118 setRtcpMux: sinon.stub(),119 setProfile: sinon.stub(),120 setBundle: sinon.stub(),121 setAudioAndVideo: sinon.stub(),122 setVideoSsrcList: sinon.stub(),123 postProcessInfo: sinon.stub(),124 hasAudio: sinon.stub(),125 hasVideo: sinon.stub(),126 };127 module.exports.WebRtcConnection = {128 init: sinon.stub(),129 close: sinon.stub(),130 createOffer: sinon.stub(),131 setRemoteSdp: sinon.stub(),132 setRemoteDescription: sinon.stub(),133 getLocalDescription: sinon.stub().returns(module.exports.ConnectionDescription),134 addRemoteCandidate: sinon.stub(),135 addMediaStream: sinon.stub(),136 removeMediaStream: sinon.stub(),137 };138 module.exports.MediaStream = {139 minVideoBW: '',140 scheme: '',141 periodicPlis: '',142 close: sinon.stub(),143 setAudioReceiver: sinon.stub(),144 setVideoReceiver: sinon.stub(),145 setMaxVideoBW: sinon.stub(),146 getStats: sinon.stub(),147 getPeriodicStats: sinon.stub(),148 generatePLIPacket: sinon.stub(),149 setSlideShowMode: sinon.stub(),150 muteStream: sinon.stub(),151 onMediaStreamEvent: sinon.stub(),152 };153 module.exports.ExternalInput = {154 init: sinon.stub(),155 setAudioReceiver: sinon.stub(),156 setVideoReceiver: sinon.stub()157 };158 module.exports.ExternalOutput = {159 init: sinon.stub(),160 close: sinon.stub()161 };162 module.exports.erizoAPI = createMock('../../erizoAPI/build/Release/addon', {163 OneToManyProcessor: sinon.stub().returns(module.exports.OneToManyProcessor),164 ConnectionDescription: sinon.stub().returns(module.exports.ConnectionDescription),165 WebRtcConnection: sinon.stub().returns(module.exports.WebRtcConnection),166 MediaStream: sinon.stub().returns(module.exports.MediaStream),167 ExternalInput: sinon.stub().returns(module.exports.ExternalInput),168 ExternalOutput: sinon.stub().returns(module.exports.ExternalOutput)169 });170 module.exports.roomControllerInstance = {171 addEventListener: sinon.stub(),172 addExternalInput: sinon.stub(),173 addExternalOutput: sinon.stub(),174 processSignaling: sinon.stub(),175 addPublisher: sinon.stub(),176 addSubscriber: sinon.stub(),177 removePublisher: sinon.stub(),178 removeSubscriber: sinon.stub(),179 removeSubscriptions: sinon.stub(),180 removeExternalOutput: sinon.stub()181 };182 module.exports.roomController = createMock('../erizoController/roomController', {183 RoomController: sinon.stub().returns(module.exports.roomControllerInstance)184 });185 module.exports.ecchInstance = {186 getErizoJS: sinon.stub(),187 deleteErizoJS: sinon.stub()188 };189 module.exports.ecch = createMock('../erizoController/ecCloudHandler', {190 EcCloudHandler: sinon.stub().returns(module.exports.ecchInstance)191 });192};...
kuzzle.mock.js
Source:kuzzle.mock.js
...20 // we need a deep copy here21 this.config = JSON.parse(JSON.stringify(config));22 // ========== EVENTS ==========23 // emit + pipe mocks24 sinon.stub(this, 'pipe').callsFake((...args) => {25 if (typeof args[args.length - 1] !== 'function') {26 return Bluebird.resolve(...args.slice(1));27 }28 const cb = args.pop();29 cb(null, ...args.slice(1));30 });31 sinon.stub(this, 'ask').resolves();32 sinon.stub(this, 'call');33 sinon.stub(this, 'once');34 sinon.spy(this, 'emit');35 sinon.spy(this, 'registerPluginHook');36 sinon.spy(this, 'registerPluginPipe');37 sinon.spy(this, 'onCall');38 sinon.spy(this, 'onAsk');39 sinon.spy(this, 'on');40 sinon.spy(this, 'onPipe');41 // ============================42 this.log = {43 error: sinon.stub(),44 warn: sinon.stub(),45 info: sinon.stub(),46 silly: sinon.stub(),47 debug: sinon.stub(),48 verbose: sinon.stub()49 };50 this.koncorde = {51 getFilterIds: sinon.stub().returns([]),52 getIndexes: sinon.stub().returns([]),53 hasFilterId: sinon.stub().returns(false),54 normalize: sinon.stub().returns({ id: 'foobar' }),55 register: sinon.stub().returns('foobar'),56 remove: sinon.stub(),57 store: sinon.stub().returns('foobar'),58 test: sinon.stub().returns([]),59 validate: sinon.stub(),60 };61 this.entryPoint = {62 dispatch: sinon.spy(),63 init: sinon.stub(),64 startListening: sinon.spy(),65 joinChannel: sinon.spy(),66 leaveChannel: sinon.spy()67 };68 this.funnel = {69 controllers: new Map(),70 init: sinon.spy(),71 loadPluginControllers: sinon.spy(),72 getRequestSlot: sinon.stub().returns(true),73 handleErrorDump: sinon.spy(),74 execute: sinon.stub(),75 mExecute: sinon.stub(),76 processRequest: sinon.stub().resolves(),77 checkRights: sinon.stub(),78 getEventName: sinon.spy(),79 executePluginRequest: sinon.stub().resolves(),80 isNativeController: sinon.stub()81 };82 this.dumpGenerator = {83 dump: sinon.stub().resolves()84 };85 this.shutdown = sinon.stub();86 const InternalIndexHandlerMock = require('./internalIndexHandler.mock');87 this.internalIndex = new InternalIndexHandlerMock();88 this.passport = {89 use: sinon.stub(),90 unuse: sinon.stub(),91 authenticate: sinon.stub().resolves({}),92 injectAuthenticateOptions: sinon.stub()93 };94 this.pluginsManager = {95 controllers: new Map(),96 init: sinon.stub().resolves(),97 plugins: [],98 run: sinon.stub().resolves(),99 getPluginsDescription: sinon.stub().returns({}),100 listStrategies: sinon.stub().returns([]),101 getActions: sinon.stub(),102 getControllerNames: sinon.stub(),103 isController: sinon.stub(),104 isAction: sinon.stub(),105 exists: sinon.stub(),106 getStrategyFields: sinon.stub().resolves(),107 getStrategyMethod: sinon.stub().returns(sinon.stub()),108 hasStrategyMethod: sinon.stub().returns(false),109 strategies: {},110 registerStrategy: sinon.stub(),111 unregisterStrategy: sinon.stub(),112 application: {113 info: sinon.stub(),114 name: 'my-app',115 },116 routes: [],117 loadedPlugins: []118 };119 this.rootPath = '/kuzzle';120 this.router = {121 connections: new Map(),122 execute: sinon.stub().resolves(foo),123 isConnectionAlive: sinon.stub().returns(true),124 init: sinon.spy(),125 newConnection: sinon.stub().resolves(foo),126 removeConnection: sinon.spy(),127 http: {128 route: sinon.stub()129 }130 };131 this.start = sinon.stub().resolves();132 this.statistics = {133 completedRequest: sinon.spy(),134 newConnection: sinon.stub(),135 failedRequest: sinon.spy(),136 getAllStats: sinon.stub().resolves(foo),137 getLastStats: sinon.stub().resolves(foo),138 getStats: sinon.stub().resolves(foo),139 init: sinon.spy(),140 dropConnection: sinon.stub(),141 startRequest: sinon.spy()142 };143 this.tokenManager = {144 init: sinon.stub().resolves(),145 expire: sinon.stub(),146 getConnectedUserToken: sinon.stub(),147 link: sinon.stub(),148 refresh: sinon.stub(),149 unlink: sinon.stub(),150 getKuidFromConnection: sinon.stub(),151 removeConnection: sinon.stub().resolves(),152 };153 this.validation = {154 addType: sinon.spy(),155 curateSpecification: sinon.stub().resolves(),156 init: sinon.spy(),157 validateFormat: sinon.stub().resolves({ isValid: false }),158 validate: sinon.stub().callsFake((...args) => Bluebird.resolve(args[0]))159 };160 this.vault = {161 init: sinon.stub(),162 prepareCrypto: sinon.stub(),163 secrets: {164 aws: {165 secretKeyId: 'the cake is a lie'166 },167 kuzzleApi: 'the spoon does not exist'168 }169 };170 this.adminExists = sinon.stub().resolves();171 this.dump = sinon.stub().resolves();172 this.asyncStore = {173 run: sinon.stub().yields(),174 set: sinon.stub(),175 exists: sinon.stub(),176 has: sinon.stub(),177 get: sinon.stub(),178 };179 this.start = sinon.stub().resolves();180 this.hash = sinon.stub().callsFake(obj => JSON.stringify(obj));181 this.running = sinon.stub().returns(false);182 }183}...
productDecoratorsMock.js
Source:productDecoratorsMock.js
1'use strict';2var proxyquire = require('proxyquire').noCallThru().noPreserveCache();3var sinon = require('sinon');4var stubBase = sinon.stub();5var stubPrice = sinon.stub();6var stubImages = sinon.stub();7var stubAvailability = sinon.stub();8var stubDescription = sinon.stub();9var stubSearchPrice = sinon.stub();10var stubPromotions = sinon.stub();11var stubQuantity = sinon.stub();12var stubQuantitySelector = sinon.stub();13var stubRatings = sinon.stub();14var stubSizeChart = sinon.stub();15var stubVariationAttributes = sinon.stub();16var stubSearchVariationAttributes = sinon.stub();17var stubAttributes = sinon.stub();18var stubOptions = sinon.stub();19var stubCurrentUrl = sinon.stub();20var stubReadyToOrder = sinon.stub();21var stubOnline = sinon.stub();22var stubSetReadyToOrder = sinon.stub();23var stubBundleReadyToOrder = sinon.stub();24var stubSetIndividualProducts = sinon.stub();25var stubSetProductsCollection = sinon.stub();26var stubBundledProducts = sinon.stub();27var stubBonusUnitPrice = sinon.stub();28var stubRaw = sinon.stub();29var stubPageMetaData = sinon.stub();30var stubTemplate = sinon.stub();31function proxyModel() {32 return {33 mocks: proxyquire('../../cartridges/app_storefront_base/cartridge/models/product/decorators/index', {34 '*/cartridge/models/product/decorators/base': stubBase,35 '*/cartridge/models/product/decorators/availability': stubAvailability,36 '*/cartridge/models/product/decorators/description': stubDescription,37 '*/cartridge/models/product/decorators/images': stubImages,38 '*/cartridge/models/product/decorators/price': stubPrice,39 '*/cartridge/models/product/decorators/searchPrice': stubSearchPrice,40 '*/cartridge/models/product/decorators/promotions': stubPromotions,41 '*/cartridge/models/product/decorators/quantity': stubQuantity,42 '*/cartridge/models/product/decorators/quantitySelector': stubQuantitySelector,43 '*/cartridge/models/product/decorators/ratings': stubRatings,44 '*/cartridge/models/product/decorators/sizeChart': stubSizeChart,...
share.js
Source:share.js
...46 });47};48export function stubCommands() {49 beforeEach('set up stubs', function() {50 this.addAll = sinon.stub(addAll, 'default');51 this.add = sinon.stub(add, 'default');52 this.bump = sinon.stub(bump, 'default');53 this.check = sinon.stub(check, 'default');54 this.create = sinon.stub(create, 'default');55 this.queryDeployment = sinon.stub(queryDeployment, 'default');56 this.querySignedDeployment = sinon.stub(querySignedDeployment, 'default');57 this.freeze = sinon.stub(freeze, 'default');58 this.init = sinon.stub(init, 'default');59 this.link = sinon.stub(link, 'default');60 this.unlink = sinon.stub(unlink, 'default');61 this.publish = sinon.stub(publish, 'default');62 this.push = sinon.stub(push, 'default');63 this.remove = sinon.stub(remove, 'default');64 this.session = sinon.stub(session, 'default');65 this.update = sinon.stub(update, 'default');66 this.setAdmin = sinon.stub(setAdmin, 'default');67 this.unpack = sinon.stub(unpack, 'default');68 this.transfer = sinon.stub(transfer, 'default');69 this.balance = sinon.stub(balance, 'default');70 this.sendTx = sinon.stub(sendTx, 'default');71 this.call = sinon.stub(call, 'default');72 this.accounts = sinon.stub(accounts, 'default');73 this.compiler = sinon.stub(Compiler, 'compile');74 this.transpiler = sinon.stub(transpiler, 'transpileAndSave');75 this.initializer = sinon.stub(ConfigManager, 'initNetworkConfiguration').callsFake(function(options) {76 ConfigManager.initStaticConfiguration();77 const { network, from } = Session.getOptions(options);78 const txParams = from ? { from } : {};79 return { network, txParams };80 });81 this.getManifestVersion = sinon.stub(NetworkFile, 'getManifestVersion').returns('2.2');82 this.projectFile = sinon.stub(ProjectFile.prototype, 'exists').returns(true);83 const projectFile = new ProjectFile('mocks/mock-stdlib/zos.json');84 this.dependency = sinon.stub(Dependency.prototype, 'projectFile').get(function getterFn() {85 return projectFile;86 });87 this.report = sinon.stub(Telemetry, 'report');88 });89 afterEach('restore', function() {90 sinon.restore();91 program.parseReset();92 });93}94export function itShouldParse(name, cmd, args, cb) {95 it(name, function(done) {96 this[cmd].onFirstCall().callsFake(() => {97 let err;98 try {99 cb(this[cmd]);100 } catch (e) {101 err = e;...
Using AI Code Generation
1const test = require('ava');2const sinon = require('sinon');3const proxyquire = require('proxyquire');4const { moviesMock, MoviesServiceMock } = require('../utils/mocks/movies');5const testServer = require('../utils/testServer');6test.beforeEach((t) => {7 t.context = {8 };9 t.context.request = testServer(t.context.moviesService);10});11test.afterEach.always((t) => {12});13test('movies GET', async (t) => {14 const response = await t.context.request.get('/api/movies');15 t.deepEqual(response.status, 200);16 t.deepEqual(response.body, {17 });18});19test('GET /api/movies/:movieId', async (t) => {20 const response = await t.context.request.get('/api/movies/1');21 t.deepEqual(response.status, 200);22 t.deepEqual(response.body, {23 });24});25test('POST /api/movies', async (t) => {26 const response = await t.context.request.post('/api/movies').send(moviesMock[0]);27 t.deepEqual(response.status, 201);28 t.deepEqual(response.body, {29 });30});31test('PUT /api/movies/:movieId', async (t) => {32 const response = await t.context.request.put('/api/movies/1').send(moviesMock[0]);33 t.deepEqual(response.status, 200);34 t.deepEqual(response.body, {
Using AI Code Generation
1test("test", t => {2 const stub = sinon.stub();3 stub.withArgs(42).returns(1);4 stub.withArgs("foo").throws("bar");5 t.is(stub(42), 1);6 t.throws(() => {7 stub("foo");8 }, "bar");9});10test("test", t => {11 const stub = sinon.stub();12 stub.withArgs(42).returns(1);13 stub.withArgs("foo").throws("bar");14 t.is(stub(42), 1);15 t.throws(() => {16 stub("foo");17 }, "bar");18});19test("test", t => {20 const stub = sinon.stub();21 stub.withArgs(42).returns(1);22 stub.withArgs("foo").throws("bar");23 t.is(stub(42), 1);24 t.throws(() => {25 stub("foo");26 }, "bar");27});28test("test", t => {29 const stub = sinon.stub();30 stub.withArgs(42).returns(1);31 stub.withArgs("foo").throws("bar");32 t.is(stub(42), 1);33 t.throws(() => {34 stub("foo");35 }, "bar");36});37test("test", t => {38 const stub = sinon.stub();39 stub.withArgs(42).returns(1);40 stub.withArgs("foo").throws("bar");41 t.is(stub(42), 1);42 t.throws(() => {43 stub("foo");44 }, "bar");45});46test("test", t => {47 const stub = sinon.stub();48 stub.withArgs(42).returns(1);49 stub.withArgs("foo").throws("bar");50 t.is(stub(42), 1);51 t.throws(() => {52 stub("foo");53 }, "bar");54});55test("test", t => {56 const stub = sinon.stub();57 stub.withArgs(42).returns(1);58 stub.withArgs("foo").throws("bar");59 t.is(stub(42), 1);
Using AI Code Generation
1import test from 'ava';2import sinon from 'sinon';3import { add } from './math';4test('add', t => {5 const addStub = sinon.stub().returns(5);6 t.is(add(addStub, 3, 2), 5);7 t.true(addStub.calledOnce);8 t.true(addStub.calledWith(3, 2));9});10import test from 'ava';11import sinon from 'sinon';12import { add } from './math';13test('add', t => {14 const addStub = sinon.stub().returns(5);15 t.is(add(addStub, 3, 2), 5);16 t.true(addStub.calledOnce);17 t.true(addStub.calledWith(3, 2));18});19import test from 'ava';20import sinon from 'sinon';21import { add } from './math';22test('add', t => {23 const addStub = sinon.stub().returns(5);24 t.is(add(addStub, 3, 2), 5);25 t.true(addStub.calledOnce);26 t.true(addStub.calledWith(3, 2));27});28import test from 'ava';29import sinon from 'sinon';30import { add } from './math';31test('add', t => {32 const addStub = sinon.stub().returns(5);33 t.is(add(addStub, 3, 2), 5);34 t.true(addStub.calledOnce);35 t.true(addStub.calledWith(3, 2));36});37import test from 'ava';38import sinon from 'sinon';39import { add } from './math';40test('add', t => {41 const addStub = sinon.stub().returns(5);42 t.is(add(addStub, 3, 2), 5);43 t.true(addStub.calledOnce);44 t.true(addStub.calledWith(3, 2));45});46import test from 'ava';47import sinon from 'sinon';48import { add } from './math';49test('add', t => {
Using AI Code Generation
1const test = require('ava')2const sinon = require('sinon')3const myAPI = require('./myAPI')4test('myAPI', async t => {5 const callback = sinon.stub()6 callback.withArgs(42).resolves('hello')7 const result = await myAPI(42, callback)8 t.is(result, 'hello')9})10const test = require('ava')11const sinon = require('sinon')12const myAPI = require('./myAPI')13test('myAPI', async t => {14 const callback = sinon.stub()15 callback.withArgs(42).resolves('hello')16 const result = await myAPI(42, callback)17 t.is(result, 'hello')18})19const test = require('ava')20const sinon = require('sinon')21const myAPI = require('./myAPI')22test('myAPI', async t => {23 const callback = sinon.stub()24 callback.withArgs(42).resolves('hello')25 const result = await myAPI(42, callback)26 t.is(result, 'hello')27})28const test = require('ava')29const sinon = require('sinon')30const myAPI = require('./myAPI')31test('myAPI', async t => {32 const callback = sinon.stub()33 callback.withArgs(42).resolves('hello')34 const result = await myAPI(42, callback)35 t.is(result, 'hello')36})37const test = require('ava')38const sinon = require('sinon')39const myAPI = require('./myAPI')40test('myAPI', async t => {41 const callback = sinon.stub()42 callback.withArgs(42).resolves('hello')43 const result = await myAPI(42, callback)44 t.is(result, 'hello')45})46const test = require('ava')47const sinon = require('sinon')48const myAPI = require('./myAPI')49test('myAPI', async t => {50 const callback = sinon.stub()51 callback.withArgs(42).resolves('hello')
Using AI Code Generation
1test('stub', t => {2 const obj = { a: 1, b: 2 };3 const stub = sinon.stub(obj, 'a').value(3);4 t.is(obj.a, 3);5 stub.restore();6 t.is(obj.a, 1);7});8test('spy', t => {9 const callback = sinon.spy();10 callback();11 callback();12 t.is(callback.callCount, 2);13});14test('mock', t => {15 const obj = { a: 1, b: 2 };16 const expectation = sinon.mock(obj).expects('a').once().withExactArgs(3);17 obj.a(3);18 expectation.verify();19});20test('match', t => {21 const obj = { a: 1, b: 2 };22 const spy = sinon.spy();23 spy(obj);24 t.true(spy.calledWith(sinon.match({ a: 1 })));25});26test('fake', t => {27 const callback = sinon.fake();28 callback(1, 2, 3);29 t.true(callback.calledWith(1, 2, 3));30});31test('fake.resolves', async t => {32 const promise = sinon.fake.resolves(42);33 t.is(await promise(), 42);34});35test('fake.rejects', async t => {36 const promise = sinon.fake.rejects(new Error('foo'));37 await t.throwsAsync(promise, { message: 'foo' });38});39test('useFakeTimers', t => {40 const clock = sinon.useFakeTimers();41 setTimeout(() => {42 t.pass();43 }, 1000);44 clock.tick(1000);45 clock.restore();46});47test('useFakeXMLHttpRequest', t => {48 const xhr = sinon.useFakeXMLHttpRequest();49 const requests = [];50 xhr.onCreate = request => requests.push(request);51 const req = new XMLHttpRequest();52 req.open('GET', '/');53 req.send();
Using AI Code Generation
1import test from 'ava';2import sinon from 'sinon';3import { EventEmitter } from 'events';4test.cb('emits a response', t => {5 const stub = sinon.stub();6 const emitter = new EventEmitter();7 emitter.on('response', stub);8 emitter.emit('response', 'foo');9 t.true(stub.calledWith('foo'));10 t.end();11});12import test from 'ava';13import sinon from 'sinon';14import { EventEmitter } from 'events';15test.cb('emits a response', t => {16 const stub = sinon.stub();17 const emitter = new EventEmitter();18 emitter.on('response', stub);19 emitter.emit('response', 'foo');20 t.true(stub.calledWith('foo'));21 t.end();22});23import test from 'ava';24import sinon from 'sinon';25import { EventEmitter } from 'events';26test.cb('emits a response', t => {27 const stub = sinon.stub();28 const emitter = new EventEmitter();29 emitter.on('response', stub);30 emitter.emit('response', 'foo');31 t.true(stub.calledWith('foo'));32 t.end();33});34import test from 'ava';35import sinon from 'sinon';36import { EventEmitter } from 'events';37test.cb('emits a response', t => {38 const stub = sinon.stub();39 const emitter = new EventEmitter();40 emitter.on('response', stub);41 emitter.emit('response', 'foo');42 t.true(stub.calledWith('foo'));43 t.end();44});45import test from 'ava';46import sinon from 'sinon';47import { EventEmitter } from 'events';48test.cb('emits a response', t => {49 const stub = sinon.stub();50 const emitter = new EventEmitter();51 emitter.on('response', stub);52 emitter.emit('response', 'foo');53 t.true(stub.calledWith('foo'));54 t.end();55});56import test from 'ava';57import sinon from 'sinon';58import { EventEmitter } from 'events';59test.cb('emits a response', t => {60 const stub = sinon.stub();61 const emitter = new EventEmitter();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!