How to use _enqueue method in root

Best JavaScript code snippet using root

item.js

Source:item.js Github

copy

Full Screen

1var request = require("request");2var qs = require("querystring");3var uuid = require("uuid");4var should = require("should");5var sinon = require("sinon");6var url = require("url");7var ua = require("../lib/index.js");8var utils = require("../lib/utils.js")9var config = require("../lib/config.js")10describe("ua", function () {11 describe("#item", function () {12 var _enqueue;13 beforeEach(function () {14 _enqueue = sinon.stub(ua.Visitor.prototype, "_enqueue", function (type, params, fn) {15 if (fn) {16 (typeof fn).should.equal('function', "#_enqueue should receive a callback")17 fn();18 }19 return this;20 });21 });22 afterEach(function () {23 _enqueue.restore()24 });25 it("should be available via the #i shortcut", function () {26 var visitor = ua()27 visitor.i.should.equal(visitor.item)28 });29 it("should accept arguments (price) when chained to transaction", function () {30 var transaction = Math.random().toString();31 var price = Math.random();32 var visitor = ua().transaction(transaction);33 var result = visitor.item(price);34 visitor._context = result._context;35 result.should.eql(visitor, "should return a visitor that is identical except for the context");36 result.should.be.instanceof(ua.Visitor);37 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")38 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");39 _enqueue.args[0][0].should.equal("transaction");40 _enqueue.args[1][0].should.equal("item");41 _enqueue.args[1][1].should.have.keys("ti", "ip")42 _enqueue.args[1][1].ti.should.equal(transaction);43 _enqueue.args[1][1].ip.should.equal(price);44 });45 it("should accept arguments (price, fn) when chained to transaction", function () {46 var transaction = Math.random().toString();47 var price = Math.random();48 var fn = sinon.spy()49 var visitor = ua().transaction(transaction);50 var result = visitor.item(price, fn);51 visitor._context = result._context;52 result.should.eql(visitor, "should return a visitor that is identical except for the context");53 result.should.be.instanceof(ua.Visitor);54 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")55 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");56 _enqueue.args[0][0].should.equal("transaction");57 _enqueue.args[1][0].should.equal("item");58 _enqueue.args[1][1].should.have.keys("ti", "ip")59 _enqueue.args[1][1].ti.should.equal(transaction);60 _enqueue.args[1][1].ip.should.equal(price);61 fn.calledOnce.should.equal(true, "callback should have been called once")62 });63 it("should accept arguments (price, quantity) when chained to transaction", function () {64 var transaction = Math.random().toString();65 var price = Math.random();66 var quantity = Math.random();67 var visitor = ua().transaction(transaction);68 var result = visitor.item(price, quantity);69 visitor._context = result._context;70 result.should.eql(visitor, "should return a visitor that is identical except for the context");71 result.should.be.instanceof(ua.Visitor);72 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")73 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");74 _enqueue.args[0][0].should.equal("transaction");75 _enqueue.args[1][0].should.equal("item");76 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq")77 _enqueue.args[1][1].ti.should.equal(transaction);78 _enqueue.args[1][1].ip.should.equal(price);79 _enqueue.args[1][1].iq.should.equal(quantity);80 });81 it("should accept arguments (price, quantity, fn) when chained to transaction", function () {82 var transaction = Math.random().toString();83 var price = Math.random();84 var quantity = Math.random();85 var fn = sinon.spy()86 var visitor = ua().transaction(transaction);87 var result = visitor.item(price, quantity, fn);88 visitor._context = result._context;89 result.should.eql(visitor, "should return a visitor that is identical except for the context");90 result.should.be.instanceof(ua.Visitor);91 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")92 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");93 _enqueue.args[0][0].should.equal("transaction");94 _enqueue.args[1][0].should.equal("item");95 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq")96 _enqueue.args[1][1].ti.should.equal(transaction);97 _enqueue.args[1][1].ip.should.equal(price);98 _enqueue.args[1][1].iq.should.equal(quantity);99 fn.calledOnce.should.equal(true, "callback should have been called once")100 });101 it("should accept arguments (price, quantity, sku) when chained to transaction", function () {102 var transaction = Math.random().toString();103 var price = Math.random();104 var quantity = Math.random();105 var sku = Math.random().toString();106 var visitor = ua().transaction(transaction);107 var result = visitor.item(price, quantity, sku);108 visitor._context = result._context;109 result.should.eql(visitor, "should return a visitor that is identical except for the context");110 result.should.be.instanceof(ua.Visitor);111 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")112 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");113 _enqueue.args[0][0].should.equal("transaction");114 _enqueue.args[1][0].should.equal("item");115 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic")116 _enqueue.args[1][1].ti.should.equal(transaction);117 _enqueue.args[1][1].ip.should.equal(price);118 _enqueue.args[1][1].iq.should.equal(quantity);119 _enqueue.args[1][1].ic.should.equal(sku);120 });121 it("should accept arguments (price, quantity, sku, fn) when chained to transaction", function () {122 var transaction = Math.random().toString();123 var price = Math.random();124 var quantity = Math.random();125 var sku = Math.random().toString();126 var fn = sinon.spy()127 var visitor = ua().transaction(transaction);128 var result = visitor.item(price, quantity, sku, fn);129 visitor._context = result._context;130 result.should.eql(visitor, "should return a visitor that is identical except for the context");131 result.should.be.instanceof(ua.Visitor);132 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")133 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");134 _enqueue.args[0][0].should.equal("transaction");135 _enqueue.args[1][0].should.equal("item");136 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic")137 _enqueue.args[1][1].ti.should.equal(transaction);138 _enqueue.args[1][1].ip.should.equal(price);139 _enqueue.args[1][1].iq.should.equal(quantity);140 _enqueue.args[1][1].ic.should.equal(sku);141 fn.calledOnce.should.equal(true, "callback should have been called once")142 });143 it("should accept arguments (price, quantity, sku, name) when chained to transaction", function () {144 var transaction = Math.random().toString();145 var price = Math.random();146 var quantity = Math.random();147 var sku = Math.random().toString();148 var name = Math.random().toString();149 var visitor = ua().transaction(transaction);150 var result = visitor.item(price, quantity, sku, name);151 visitor._context = result._context;152 result.should.eql(visitor, "should return a visitor that is identical except for the context");153 result.should.be.instanceof(ua.Visitor);154 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")155 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");156 _enqueue.args[0][0].should.equal("transaction");157 _enqueue.args[1][0].should.equal("item");158 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic", "in")159 _enqueue.args[1][1].ti.should.equal(transaction);160 _enqueue.args[1][1].ip.should.equal(price);161 _enqueue.args[1][1].iq.should.equal(quantity);162 _enqueue.args[1][1].ic.should.equal(sku);163 _enqueue.args[1][1].in.should.equal(name);164 });165 it("should accept arguments (price, quantity, sku, name, fn) when chained to transaction", function () {166 var transaction = Math.random().toString();167 var price = Math.random();168 var quantity = Math.random();169 var sku = Math.random().toString();170 var name = Math.random().toString();171 var fn = sinon.spy()172 var visitor = ua().transaction(transaction);173 var result = visitor.item(price, quantity, sku, name, fn);174 visitor._context = result._context;175 result.should.eql(visitor, "should return a visitor that is identical except for the context");176 result.should.be.instanceof(ua.Visitor);177 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")178 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");179 _enqueue.args[0][0].should.equal("transaction");180 _enqueue.args[1][0].should.equal("item");181 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic", "in")182 _enqueue.args[1][1].ti.should.equal(transaction);183 _enqueue.args[1][1].ip.should.equal(price);184 _enqueue.args[1][1].iq.should.equal(quantity);185 _enqueue.args[1][1].ic.should.equal(sku);186 _enqueue.args[1][1].in.should.equal(name);187 fn.calledOnce.should.equal(true, "callback should have been called once")188 });189 it("should accept arguments (price, quantity, sku, name, variation) when chained to transaction", function () {190 var transaction = Math.random().toString();191 var price = Math.random();192 var quantity = Math.random();193 var sku = Math.random().toString();194 var name = Math.random().toString();195 var variation = Math.random().toString();196 var visitor = ua().transaction(transaction);197 var result = visitor.item(price, quantity, sku, name, variation);198 visitor._context = result._context;199 result.should.eql(visitor, "should return a visitor that is identical except for the context");200 result.should.be.instanceof(ua.Visitor);201 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")202 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");203 _enqueue.args[0][0].should.equal("transaction");204 _enqueue.args[1][0].should.equal("item");205 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic", "in", "iv")206 _enqueue.args[1][1].ti.should.equal(transaction);207 _enqueue.args[1][1].ip.should.equal(price);208 _enqueue.args[1][1].iq.should.equal(quantity);209 _enqueue.args[1][1].ic.should.equal(sku);210 _enqueue.args[1][1].in.should.equal(name);211 _enqueue.args[1][1].iv.should.equal(variation);212 });213 it("should accept arguments (price, quantity, sku, name, variation, fn) when chained to transaction", function () {214 var transaction = Math.random().toString();215 var price = Math.random();216 var quantity = Math.random();217 var sku = Math.random().toString();218 var name = Math.random().toString();219 var variation = Math.random().toString();220 var fn = sinon.spy()221 var visitor = ua().transaction(transaction);222 var result = visitor.item(price, quantity, sku, name, variation, fn);223 visitor._context = result._context;224 result.should.eql(visitor, "should return a visitor that is identical except for the context");225 result.should.be.instanceof(ua.Visitor);226 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")227 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");228 _enqueue.args[0][0].should.equal("transaction");229 _enqueue.args[1][0].should.equal("item");230 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic", "in", "iv")231 _enqueue.args[1][1].ti.should.equal(transaction);232 _enqueue.args[1][1].ip.should.equal(price);233 _enqueue.args[1][1].iq.should.equal(quantity);234 _enqueue.args[1][1].ic.should.equal(sku);235 _enqueue.args[1][1].in.should.equal(name);236 _enqueue.args[1][1].iv.should.equal(variation);237 fn.calledOnce.should.equal(true, "callback should have been called once")238 });239 it("should accept arguments (price, quantity, sku, name, variation, params) when chained to transaction", function () {240 var transaction = Math.random().toString();241 var price = Math.random();242 var quantity = Math.random();243 var sku = Math.random().toString();244 var name = Math.random().toString();245 var variation = Math.random().toString();246 var params = {foo: Math.random().toString()};247 var visitor = ua().transaction(transaction);248 var result = visitor.item(price, quantity, sku, name, variation, params);249 visitor._context = result._context;250 result.should.eql(visitor, "should return a visitor that is identical except for the context");251 result.should.be.instanceof(ua.Visitor);252 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")253 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");254 _enqueue.args[0][0].should.equal("transaction");255 _enqueue.args[1][0].should.equal("item");256 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic", "in", "iv", "foo")257 _enqueue.args[1][1].ti.should.equal(transaction);258 _enqueue.args[1][1].ip.should.equal(price);259 _enqueue.args[1][1].iq.should.equal(quantity);260 _enqueue.args[1][1].ic.should.equal(sku);261 _enqueue.args[1][1].in.should.equal(name);262 _enqueue.args[1][1].iv.should.equal(variation);263 _enqueue.args[1][1].foo.should.equal(params.foo);264 });265 it("should accept arguments (price, quantity, sku, name, variation, params, fn) when chained to transaction", function () {266 var transaction = Math.random().toString();267 var price = Math.random();268 var quantity = Math.random();269 var sku = Math.random().toString();270 var name = Math.random().toString();271 var variation = Math.random().toString();272 var params = {foo: Math.random().toString()};273 var fn = sinon.spy()274 var visitor = ua().transaction(transaction);275 var result = visitor.item(price, quantity, sku, name, variation, params, fn);276 visitor._context = result._context;277 result.should.eql(visitor, "should return a visitor that is identical except for the context");278 result.should.be.instanceof(ua.Visitor);279 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")280 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction before");281 _enqueue.args[0][0].should.equal("transaction");282 _enqueue.args[1][0].should.equal("item");283 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic", "in", "iv", "foo")284 _enqueue.args[1][1].ti.should.equal(transaction);285 _enqueue.args[1][1].ip.should.equal(price);286 _enqueue.args[1][1].iq.should.equal(quantity);287 _enqueue.args[1][1].ic.should.equal(sku);288 _enqueue.args[1][1].in.should.equal(name);289 _enqueue.args[1][1].iv.should.equal(variation);290 _enqueue.args[1][1].foo.should.equal(params.foo);291 fn.calledOnce.should.equal(true, "callback should have been called once")292 });293 it("should accept arguments (price, quantity, sku, name, variation, params, fn) when params include transaction", function () {294 var price = Math.random();295 var quantity = Math.random();296 var sku = Math.random().toString();297 var name = Math.random().toString();298 var variation = Math.random().toString();299 var params = {ti: Math.random()};300 var fn = sinon.spy()301 var visitor = ua();302 var result = visitor.item(price, quantity, sku, name, variation, params, fn);303 visitor._context = result._context;304 result.should.eql(visitor, "should return a visitor that is identical except for the context");305 result.should.be.instanceof(ua.Visitor);306 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")307 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");308 _enqueue.args[0][0].should.equal("item");309 _enqueue.args[0][1].should.have.keys("ti", "ip", "iq", "ic", "in", "iv")310 _enqueue.args[0][1].ip.should.equal(price);311 _enqueue.args[0][1].iq.should.equal(quantity);312 _enqueue.args[0][1].ic.should.equal(sku);313 _enqueue.args[0][1].in.should.equal(name);314 _enqueue.args[0][1].iv.should.equal(variation);315 _enqueue.args[0][1].ti.should.equal(params.ti);316 fn.calledOnce.should.equal(true, "callback should have been called once")317 });318 it("should accept arguments (params, fn) when params include transaction", function () {319 var params = {320 ip: Math.random(),321 iq: Math.random(),322 ic: Math.random().toString(),323 in: Math.random().toString(),324 iv: Math.random().toString(),325 ti: Math.random()326 };327 var fn = sinon.spy()328 var visitor = ua();329 var result = visitor.item(params, fn);330 visitor._context = result._context;331 result.should.eql(visitor, "should return a visitor that is identical except for the context");332 result.should.be.instanceof(ua.Visitor);333 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")334 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");335 _enqueue.args[0][0].should.equal("item");336 _enqueue.args[0][1].should.have.keys("ti", "ip", "iq", "ic", "in", "iv")337 _enqueue.args[0][1].ip.should.equal(params.ip);338 _enqueue.args[0][1].iq.should.equal(params.iq);339 _enqueue.args[0][1].ic.should.equal(params.ic);340 _enqueue.args[0][1].in.should.equal(params.in);341 _enqueue.args[0][1].iv.should.equal(params.iv);342 _enqueue.args[0][1].ti.should.equal(params.ti);343 fn.calledOnce.should.equal(true, "callback should have been called once")344 });345 it("should accept arguments (params, fn) when chained to a transaction", function () {346 var transaction = Math.random().toString();347 var params = {348 ip: Math.random(),349 iq: Math.random(),350 ic: Math.random().toString(),351 in: Math.random().toString(),352 iv: Math.random().toString()353 };354 var fn = sinon.spy()355 var visitor = ua().transaction(transaction);356 var result = visitor.item(params, fn);357 visitor._context = result._context;358 result.should.eql(visitor, "should return a visitor that is identical except for the context");359 result.should.be.instanceof(ua.Visitor);360 result._context.should.eql(_enqueue.args[1][1], "the transaction params should be persisted as the context of the visitor clone")361 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for the transaction");362 _enqueue.args[1][0].should.equal("item");363 _enqueue.args[1][1].should.have.keys("ti", "ip", "iq", "ic", "in", "iv")364 _enqueue.args[1][1].ip.should.equal(params.ip);365 _enqueue.args[1][1].iq.should.equal(params.iq);366 _enqueue.args[1][1].ic.should.equal(params.ic);367 _enqueue.args[1][1].in.should.equal(params.in);368 _enqueue.args[1][1].iv.should.equal(params.iv);369 _enqueue.args[1][1].ti.should.equal(transaction);370 fn.calledOnce.should.equal(true, "callback should have been called once")371 });372 it("should allow daisy-chaining to re-use arguments", function () {373 var transaction = Math.random().toString();374 var price = Math.random();375 var quantity = Math.random();376 var sku = Math.random().toString();377 var name = Math.random().toString();378 var name2 = Math.random().toString();379 var variation = Math.random().toString();380 var fn = sinon.spy()381 var visitor = ua().transaction(transaction);382 var result = visitor.item(price, quantity, sku, name, variation).item({in: name2}, fn);383 _enqueue.calledThrice.should.equal(true, "#_enqueue should have been called thrice, once for the transaction before");384 _enqueue.args[0][0].should.equal("transaction");385 _enqueue.args[1][0].should.equal(_enqueue.args[2][0]);386 _enqueue.args[1][1].ti.should.equal(_enqueue.args[2][1].ti, "ti should be equal on both");387 _enqueue.args[1][1].ip.should.equal(_enqueue.args[2][1].ip, "ip should be equal on both");388 _enqueue.args[1][1].iq.should.equal(_enqueue.args[2][1].iq, "iq should be equal on both");389 _enqueue.args[1][1].ic.should.equal(_enqueue.args[2][1].ic, "ic should be equal on both");390 _enqueue.args[1][1].iv.should.equal(_enqueue.args[2][1].iv, "iv should be equal on both");391 _enqueue.args[2][1].in.should.equal(name2, "name should have changed on second item");392 fn.calledOnce.should.equal(true, "callback should have been called once")393 });394 it("should fail without transaction ID", function () {395 var params = {396 ip: Math.random(),397 iq: Math.random(),398 ic: Math.random().toString(),399 in: Math.random().toString(),400 iv: Math.random().toString()401 };402 var fn = sinon.spy()403 var visitor = ua();404 var result = visitor.item(params, fn);405 visitor._context = result._context;406 result.should.eql(visitor, "should return a visitor that is identical except for the context");407 result.should.be.instanceof(ua.Visitor);408 result._context.should.eql({}, "the transaction params should not be persisted")409 _enqueue.called.should.equal(false, "#_enqueue should have not been called once");410 fn.calledOnce.should.equal(true, "callback should have been called once");411 fn.args[0][0].should.be.instanceof(Error);412 fn.thisValues[0].should.equal(visitor);413 });414 });...

Full Screen

Full Screen

transaction.js

Source:transaction.js Github

copy

Full Screen

1var request = require("request");2var qs = require("querystring");3var uuid = require("uuid");4var should = require("should");5var sinon = require("sinon");6var url = require("url");7var ua = require("../lib/index.js");8var utils = require("../lib/utils.js")9var config = require("../lib/config.js")10describe("ua", function () {11 describe("#transaction", function () {12 var _enqueue;13 beforeEach(function () {14 _enqueue = sinon.stub(ua.Visitor.prototype, "_enqueue", function (type, params, fn) {15 if (fn) {16 (typeof fn).should.equal('function', "#_enqueue should receive a callback")17 fn();18 }19 return this;20 });21 });22 afterEach(function () {23 _enqueue.restore()24 });25 it("should be available via the #t shortcut", function () {26 var visitor = ua()27 visitor.t.should.equal(visitor.transaction)28 });29 it("should accept arguments (transaction)", function () {30 var transaction = Math.random().toString();31 var visitor = ua()32 var result = visitor.transaction(transaction);33 visitor._context = result._context;34 result.should.eql(visitor, "should return a visitor that is identical except for the context");35 result.should.be.instanceof(ua.Visitor);36 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")37 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");38 _enqueue.args[0][0].should.equal("transaction");39 _enqueue.args[0][1].should.have.keys("ti")40 _enqueue.args[0][1].ti.should.equal(transaction);41 });42 it("should accept arguments (transaction, fn)", function () {43 var transaction = Math.random().toString();44 var fn = sinon.spy()45 ua().transaction(transaction, fn);46 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");47 _enqueue.args[0][0].should.equal("transaction");48 _enqueue.args[0][1].should.have.keys("ti")49 _enqueue.args[0][1].ti.should.equal(transaction);50 fn.calledOnce.should.equal(true, "callback should have been called once")51 });52 it("should accept arguments (transaction, revenue)", function () {53 var transaction = Math.random().toString();54 var revenue = Math.random();55 ua().transaction(transaction, revenue);56 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");57 _enqueue.args[0][0].should.equal("transaction");58 _enqueue.args[0][1].should.have.keys("ti", "tr")59 _enqueue.args[0][1].ti.should.equal(transaction);60 _enqueue.args[0][1].tr.should.equal(revenue);61 });62 it("should accept arguments (transaction, revenue, fn)", function () {63 var transaction = Math.random().toString();64 var revenue = Math.random();65 var fn = sinon.spy()66 ua().transaction(transaction, revenue, fn);67 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");68 _enqueue.args[0][0].should.equal("transaction");69 _enqueue.args[0][1].should.have.keys("ti", "tr")70 _enqueue.args[0][1].ti.should.equal(transaction);71 _enqueue.args[0][1].tr.should.equal(revenue);72 fn.calledOnce.should.equal(true, "callback should have been called once")73 });74 it("should accept arguments (transaction, revenue, shipping)", function () {75 var transaction = Math.random().toString();76 var revenue = Math.random();77 var shipping = Math.random();78 ua().transaction(transaction, revenue, shipping);79 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");80 _enqueue.args[0][0].should.equal("transaction");81 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts")82 _enqueue.args[0][1].ti.should.equal(transaction);83 _enqueue.args[0][1].tr.should.equal(revenue);84 _enqueue.args[0][1].ts.should.equal(shipping);85 });86 it("should accept arguments (transaction, revenue, shipping, fn)", function () {87 var transaction = Math.random().toString();88 var revenue = Math.random();89 var shipping = Math.random();90 var fn = sinon.spy()91 ua().transaction(transaction, revenue, shipping, fn);92 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");93 _enqueue.args[0][0].should.equal("transaction");94 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts")95 _enqueue.args[0][1].ti.should.equal(transaction);96 _enqueue.args[0][1].tr.should.equal(revenue);97 _enqueue.args[0][1].ts.should.equal(shipping);98 fn.calledOnce.should.equal(true, "callback should have been called once")99 });100 it("should accept arguments (transaction, revenue, shipping, tax)", function () {101 var transaction = Math.random().toString();102 var revenue = Math.random();103 var shipping = Math.random();104 var tax = Math.random();105 ua().transaction(transaction, revenue, shipping, tax);106 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");107 _enqueue.args[0][0].should.equal("transaction");108 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt")109 _enqueue.args[0][1].ti.should.equal(transaction);110 _enqueue.args[0][1].tr.should.equal(revenue);111 _enqueue.args[0][1].ts.should.equal(shipping);112 _enqueue.args[0][1].tt.should.equal(tax);113 });114 it("should accept arguments (transaction, revenue, shipping, tax, fn)", function () {115 var transaction = Math.random().toString();116 var revenue = Math.random();117 var shipping = Math.random();118 var tax = Math.random();119 var fn = sinon.spy()120 ua().transaction(transaction, revenue, shipping, tax, fn);121 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");122 _enqueue.args[0][0].should.equal("transaction");123 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt")124 _enqueue.args[0][1].ti.should.equal(transaction);125 _enqueue.args[0][1].tr.should.equal(revenue);126 _enqueue.args[0][1].ts.should.equal(shipping);127 _enqueue.args[0][1].tt.should.equal(tax);128 fn.calledOnce.should.equal(true, "callback should have been called once")129 });130 it("should accept arguments (transaction, revenue, shipping, tax, affiliation)", function () {131 var transaction = Math.random().toString();132 var revenue = Math.random();133 var shipping = Math.random();134 var tax = Math.random();135 var affiliation = Math.random().toString();136 ua().transaction(transaction, revenue, shipping, tax, affiliation);137 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");138 _enqueue.args[0][0].should.equal("transaction");139 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta")140 _enqueue.args[0][1].ti.should.equal(transaction);141 _enqueue.args[0][1].tr.should.equal(revenue);142 _enqueue.args[0][1].ts.should.equal(shipping);143 _enqueue.args[0][1].tt.should.equal(tax);144 _enqueue.args[0][1].ta.should.equal(affiliation);145 });146 it("should accept arguments (transaction, revenue, shipping, tax, affiliation, fn)", function () {147 var transaction = Math.random().toString();148 var revenue = Math.random();149 var shipping = Math.random();150 var tax = Math.random();151 var affiliation = Math.random().toString();152 var fn = sinon.spy()153 ua().transaction(transaction, revenue, shipping, tax, affiliation, fn);154 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");155 _enqueue.args[0][0].should.equal("transaction");156 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta")157 _enqueue.args[0][1].ti.should.equal(transaction);158 _enqueue.args[0][1].tr.should.equal(revenue);159 _enqueue.args[0][1].ts.should.equal(shipping);160 _enqueue.args[0][1].tt.should.equal(tax);161 _enqueue.args[0][1].ta.should.equal(affiliation);162 fn.calledOnce.should.equal(true, "callback should have been called once")163 });164 it("should accept arguments (transaction, revenue, shipping, tax, affiliation, params)", function () {165 var transaction = Math.random().toString();166 var revenue = Math.random();167 var shipping = Math.random();168 var tax = Math.random();169 var affiliation = Math.random().toString();170 var params = {p: Math.random().toString()}171 ua().transaction(transaction, revenue, shipping, tax, affiliation, params);172 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");173 _enqueue.args[0][0].should.equal("transaction");174 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")175 _enqueue.args[0][1].ti.should.equal(transaction);176 _enqueue.args[0][1].tr.should.equal(revenue);177 _enqueue.args[0][1].ts.should.equal(shipping);178 _enqueue.args[0][1].tt.should.equal(tax);179 _enqueue.args[0][1].ta.should.equal(affiliation);180 _enqueue.args[0][1].p.should.equal(params.p);181 });182 it("should accept arguments (transaction, revenue, shipping, tax, affiliation, params, fn)", function () {183 var transaction = Math.random().toString();184 var revenue = Math.random();185 var shipping = Math.random();186 var tax = Math.random();187 var affiliation = Math.random().toString();188 var params = {p: Math.random().toString()}189 var fn = sinon.spy()190 ua().transaction(transaction, revenue, shipping, tax, affiliation, params, fn);191 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");192 _enqueue.args[0][0].should.equal("transaction");193 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")194 _enqueue.args[0][1].ti.should.equal(transaction);195 _enqueue.args[0][1].tr.should.equal(revenue);196 _enqueue.args[0][1].ts.should.equal(shipping);197 _enqueue.args[0][1].tt.should.equal(tax);198 _enqueue.args[0][1].ta.should.equal(affiliation);199 _enqueue.args[0][1].p.should.equal(params.p);200 fn.calledOnce.should.equal(true, "callback should have been called once")201 });202 it("should accept arguments (params)", function () {203 var params = {204 ti: Math.random().toString(),205 tr: Math.random(),206 ts: Math.random(),207 tt: Math.random(),208 ta: Math.random().toString(),209 p: Math.random().toString(),210 empty: null // Should be removed211 };212 var json = JSON.stringify(params);213 var visitor = ua()214 var result = visitor.transaction(params);215 visitor._context = result._context;216 result.should.eql(visitor, "should return a visitor that is identical except for the context");217 result.should.be.instanceof(ua.Visitor);218 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")219 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");220 _enqueue.args[0][0].should.equal("transaction");221 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")222 _enqueue.args[0][1].ti.should.equal(params.ti);223 _enqueue.args[0][1].tr.should.equal(params.tr);224 _enqueue.args[0][1].ts.should.equal(params.ts);225 _enqueue.args[0][1].tt.should.equal(params.tt);226 _enqueue.args[0][1].ta.should.equal(params.ta);227 _enqueue.args[0][1].p.should.equal(params.p);228 JSON.stringify(params).should.equal(json, "params should not have changed");229 });230 it("should accept arguments (params, fn)", function () {231 var params = {232 ti: Math.random().toString(),233 tr: Math.random(),234 ts: Math.random(),235 tt: Math.random(),236 ta: Math.random().toString(),237 p: Math.random().toString()238 };239 var fn = sinon.spy()240 var visitor = ua()241 var result = visitor.transaction(params, fn);242 visitor._context = result._context;243 result.should.eql(visitor, "should return a visitor that is identical except for the context");244 result.should.be.instanceof(ua.Visitor);245 result._context.should.eql(_enqueue.args[0][1], "the transaction params should be persisted as the context of the visitor clone")246 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");247 _enqueue.args[0][0].should.equal("transaction");248 _enqueue.args[0][1].should.have.keys("ti", "tr", "ts", "tt", "ta", "p")249 _enqueue.args[0][1].ti.should.equal(params.ti);250 _enqueue.args[0][1].tr.should.equal(params.tr);251 _enqueue.args[0][1].ts.should.equal(params.ts);252 _enqueue.args[0][1].tt.should.equal(params.tt);253 _enqueue.args[0][1].ta.should.equal(params.ta);254 _enqueue.args[0][1].p.should.equal(params.p);255 fn.calledOnce.should.equal(true, "callback should have been called once")256 });257 it("should fail without transaction ID", function () {258 var fn = sinon.spy()259 var visitor = ua()260 var result = visitor.transaction(null, fn);261 visitor._context = result._context;262 result.should.eql(visitor, "should return a visitor that is identical except for the context");263 result.should.be.instanceof(ua.Visitor);264 result._context.should.eql({}, "the transaction params should not be persisted")265 _enqueue.called.should.equal(false, "#_enqueue should have not been called once");266 fn.calledOnce.should.equal(true, "callback should have been called once");267 fn.args[0][0].should.be.instanceof(Error);268 fn.thisValues[0].should.equal(visitor);269 });270 });...

Full Screen

Full Screen

event.js

Source:event.js Github

copy

Full Screen

1var request = require("request");2var qs = require("querystring");3var uuid = require("uuid");4var should = require("should");5var sinon = require("sinon");6var url = require("url");7var ua = require("../lib/index.js");8var utils = require("../lib/utils.js")9var config = require("../lib/config.js")10describe("ua", function () {11 describe("#event", function () {12 var _enqueue;13 beforeEach(function () {14 _enqueue = sinon.stub(ua.Visitor.prototype, "_enqueue", function () {15 if (arguments.length === 3 && typeof arguments[2] === 'function') {16 arguments[2]();17 }18 return this;19 });20 });21 afterEach(function () {22 _enqueue.restore()23 });24 it("should be available via the #e shortcut", function () {25 var visitor = ua()26 visitor.e.should.equal(visitor.event)27 });28 it("should accept arguments (category, action)", function () {29 var category = Math.random().toString();30 var action = Math.random().toString();31 var visitor = ua()32 var result = visitor.event(category, action);33 visitor._context = result._context;34 result.should.eql(visitor, "should return a visitor that is identical except for the context");35 result.should.be.instanceof(ua.Visitor);36 result._context.should.eql(_enqueue.args[0][1], "the pageview params should be persisted as the context of the visitor clone")37 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");38 _enqueue.args[0][0].should.equal("event");39 _enqueue.args[0][1].should.have.keys("ec", "ea")40 _enqueue.args[0][1].ec.should.equal(category);41 _enqueue.args[0][1].ea.should.equal(action);42 });43 it("should accept arguments (category, action, fn)", function () {44 var category = Math.random().toString();45 var action = Math.random().toString();46 var fn = sinon.spy()47 ua().event(category, action, fn);48 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");49 _enqueue.args[0][0].should.equal("event");50 _enqueue.args[0][1].should.have.keys("ec", "ea")51 _enqueue.args[0][1].ec.should.equal(category);52 _enqueue.args[0][1].ea.should.equal(action);53 fn.calledOnce.should.equal(true, "callback should have been called once")54 });55 it("should accept arguments (category, action, label)", function () {56 var category = Math.random().toString();57 var action = Math.random().toString();58 var label = Math.random().toString();59 ua().event(category, action, label);60 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");61 _enqueue.args[0][0].should.equal("event");62 _enqueue.args[0][1].should.have.keys("ec", "ea", "el")63 _enqueue.args[0][1].ec.should.equal(category);64 _enqueue.args[0][1].ea.should.equal(action);65 _enqueue.args[0][1].el.should.equal(label);66 });67 it("should accept arguments (category, action, label, fn)", function () {68 var category = Math.random().toString();69 var action = Math.random().toString();70 var label = Math.random().toString();71 var fn = sinon.spy()72 ua().event(category, action, label, fn);73 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");74 _enqueue.args[0][0].should.equal("event");75 _enqueue.args[0][1].should.have.keys("ec", "ea", "el")76 _enqueue.args[0][1].ec.should.equal(category);77 _enqueue.args[0][1].ea.should.equal(action);78 _enqueue.args[0][1].el.should.equal(label);79 fn.calledOnce.should.equal(true, "callback should have been called once")80 });81 it("should accept arguments (category, action, label, value)", function () {82 var category = Math.random().toString();83 var action = Math.random().toString();84 var label = Math.random().toString();85 var value = Math.random();86 ua().event(category, action, label, value);87 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");88 _enqueue.args[0][0].should.equal("event");89 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev")90 _enqueue.args[0][1].ec.should.equal(category);91 _enqueue.args[0][1].ea.should.equal(action);92 _enqueue.args[0][1].el.should.equal(label);93 _enqueue.args[0][1].ev.should.equal(value);94 });95 it("should accept arguments (category, action, label, value, fn)", function () {96 var category = Math.random().toString();97 var action = Math.random().toString();98 var label = Math.random().toString();99 var value = Math.random();100 var fn = sinon.spy()101 ua().event(category, action, label, value, fn);102 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");103 _enqueue.args[0][0].should.equal("event");104 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev")105 _enqueue.args[0][1].ec.should.equal(category);106 _enqueue.args[0][1].ea.should.equal(action);107 _enqueue.args[0][1].el.should.equal(label);108 _enqueue.args[0][1].ev.should.equal(value);109 fn.calledOnce.should.equal(true, "callback should have been called once")110 });111 it("should accept arguments (category, action, label, value, params, fn)", function () {112 var category = Math.random().toString();113 var action = Math.random().toString();114 var label = Math.random().toString();115 var value = Math.random();116 var params = {"p": "/" + Math.random()}117 var fn = sinon.spy()118 ua().event(category, action, label, value, params, fn);119 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");120 _enqueue.args[0][0].should.equal("event");121 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev", "p")122 _enqueue.args[0][1].ec.should.equal(category);123 _enqueue.args[0][1].ea.should.equal(action);124 _enqueue.args[0][1].el.should.equal(label);125 _enqueue.args[0][1].ev.should.equal(value);126 _enqueue.args[0][1].p.should.equal(params.p);127 fn.calledOnce.should.equal(true, "callback should have been called once")128 });129 it("should accept arguments (params)", function () {130 var params = {131 ec: Math.random().toString(),132 ea: Math.random().toString(),133 el: Math.random().toString(),134 ev: Math.random(),135 "p": "/" + Math.random(),136 "empty": null137 }138 var json = JSON.stringify(params)139 ua().event(params);140 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");141 _enqueue.args[0][0].should.equal("event");142 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev", "p")143 _enqueue.args[0][1].ec.should.equal(params.ec);144 _enqueue.args[0][1].ea.should.equal(params.ea);145 _enqueue.args[0][1].el.should.equal(params.el);146 _enqueue.args[0][1].ev.should.equal(params.ev);147 _enqueue.args[0][1].p.should.equal(params.p);148 JSON.stringify(params).should.equal(json, "params should not have been modified")149 });150 it("should accept arguments (params, fn)", function () {151 var params = {152 ec: Math.random().toString(),153 ea: Math.random().toString(),154 el: Math.random().toString(),155 ev: Math.random(),156 "p": "/" + Math.random()157 }158 var fn = sinon.spy()159 ua().event(params, fn);160 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");161 _enqueue.args[0][0].should.equal("event");162 _enqueue.args[0][1].should.have.keys("ec", "ea", "el", "ev", "p")163 _enqueue.args[0][1].ec.should.equal(params.ec);164 _enqueue.args[0][1].ea.should.equal(params.ea);165 _enqueue.args[0][1].el.should.equal(params.el);166 _enqueue.args[0][1].ev.should.equal(params.ev);167 _enqueue.args[0][1].p.should.equal(params.p);168 fn.calledOnce.should.equal(true, "callback should have been called once")169 });170 it("should use the dp attribute as p for providing a event path", function () {171 var params = {172 ec: Math.random().toString(),173 ea: Math.random().toString(),174 "dp": "/" + Math.random(),175 }176 var json = JSON.stringify(params)177 ua().event(params);178 _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");179 _enqueue.args[0][0].should.equal("event");180 _enqueue.args[0][1].should.have.keys("ec", "ea", "p")181 _enqueue.args[0][1].ec.should.equal(params.ec);182 _enqueue.args[0][1].ea.should.equal(params.ea);183 _enqueue.args[0][1].p.should.equal(params.dp);184 JSON.stringify(params).should.equal(json, "params should not have been modified")185 });186 it("should allow daisy-chaining and re-using parameters", function () {187 var params = {188 ec: Math.random().toString(),189 ea: Math.random().toString(),190 el: Math.random().toString(),191 ev: Math.random()192 }193 ua().event(params).event()194 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for each event");195 _enqueue.args[0][0].should.equal(_enqueue.args[1][0]);196 _enqueue.args[0][1].ec.should.equal(_enqueue.args[1][1].ec);197 _enqueue.args[0][1].ea.should.equal(_enqueue.args[1][1].ea);198 _enqueue.args[0][1].el.should.equal(_enqueue.args[1][1].el);199 _enqueue.args[0][1].ev.should.equal(_enqueue.args[1][1].ev);200 });201 it("should extend and overwrite params when daisy-chaining", function () {202 var params = {203 ec: Math.random().toString(),204 ea: Math.random().toString(),205 el: Math.random().toString(),206 ev: Math.random()207 }208 var category = Math.random().toString();209 ua().event(params).event(category)210 _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for each event");211 _enqueue.args[0][0].should.equal(_enqueue.args[1][0]);212 _enqueue.args[0][1].ea.should.equal(_enqueue.args[1][1].ea);213 _enqueue.args[0][1].el.should.equal(_enqueue.args[1][1].el);214 _enqueue.args[0][1].ev.should.equal(_enqueue.args[1][1].ev);215 _enqueue.args[0][1].ec.should.equal(params.ec);216 _enqueue.args[1][1].ec.should.equal(category);217 });218 it("should re-use the path when daisy-chained to a pageview", function () {219 var path = "/" + Math.random()220 var params = {221 ec: Math.random().toString(),222 ea: Math.random().toString(),223 el: Math.random().toString(),224 ev: Math.random()225 }226 ua().pageview(path).event(params).event(params);227 _enqueue.calledThrice.should.equal(true, "#_enqueue should have been called twice, once for the pageview, once for the pageview");228 _enqueue.args[1][1].p.should.equal(path)229 _enqueue.args[2][1].p.should.equal(path)230 })231 it("should fail without event category", function () {232 var fn = sinon.spy()233 var action = Math.random().toString();234 var visitor = ua()235 var result = visitor.event(null, action, fn);236 visitor._context = result._context;237 result.should.eql(visitor, "should return a visitor that is identical except for the context");238 result.should.be.instanceof(ua.Visitor);239 result._context.should.eql({}, "the transaction params should not be persisted")240 _enqueue.called.should.equal(false, "#_enqueue should have not been called once");241 fn.calledOnce.should.equal(true, "callback should have been called once");242 fn.args[0][0].should.be.instanceof(Error);243 fn.thisValues[0].should.equal(visitor);244 });245 it("should fail without event action", function () {246 var fn = sinon.spy()247 var category = Math.random().toString();248 var visitor = ua()249 var result = visitor.event(category, null, fn);250 visitor._context = result._context;251 result.should.eql(visitor, "should return a visitor that is identical except for the context");252 result.should.be.instanceof(ua.Visitor);253 result._context.should.eql({}, "the transaction params should not be persisted")254 _enqueue.called.should.equal(false, "#_enqueue should have not been called once");255 fn.calledOnce.should.equal(true, "callback should have been called once");256 fn.args[0][0].should.be.instanceof(Error);257 fn.thisValues[0].should.equal(visitor);258 });259 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1class Queue {2 constructor() {3 this._storage = {};4 this._head = 0;5 this._tail = 0;6 }7 _enqueue(value) {8 this._storage[this._tail] = value;9 this._tail++;10 }11 _dequeue() {12 if (this._head < this._tail) {13 let result = this._storage[this._head];14 delete this._storage[this._head];15 this._head++;16 return result;17 }18 }19 _size() {20 return this._tail - this._head;21 }22 _isEmpty() {23 return this._head === this._tail;24 }25 _contains(value) {26 for (let key in this._storage) {27 if (this._storage[key] === value) {28 return true;29 }30 }31 return false;32 }33}34class QueueNode {35 constructor(value) {36 this.value = value;37 this.next = null;38 }39}40class QueueWithLinkedList {41 constructor() {42 this._storage = {};43 this._head = null;44 this._tail = null;45 }46 _enqueue(value) {47 let node = new QueueNode(value);48 if (this._head === null) {49 this._head = node;50 this._tail = node;51 } else {52 this._tail.next = node;53 this._tail = node;54 }55 }56 _dequeue() {57 if (this._head !== null) {58 let result = this._head.value;59 if (this._head === this._tail) {60 this._head = null;61 this._tail = null;62 } else {63 this._head = this._head.next;64 }65 return result;66 }67 }68 _size() {69 let counter = 0;70 let current = this._head;71 while (current !== null) {72 counter++;73 current = current.next;74 }75 return counter;76 }77 _isEmpty()

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = class Queue {2 constructor() {3 this.items = [];4 }5 _enqueue(item) {6 this.items.push(item);7 }8 _dequeue() {9 return this.items.shift();10 }11 _size() {12 return this.items.length;13 }14};15const Queue = require('./queue');16module.exports = class Root {17 constructor() {18 this.queue = new Queue();19 }20};

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 root 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