Best Python code snippet using keyboard
deploy_test.js
Source:deploy_test.js
1'use strict';2const assert = require('chai').assert;3const expect = require('chai').expect;4const sinon = require('sinon');5const datastore = require('../datastore');6const deploy = require('../deploy');7const google = require('googleapis');8const sandbox = sinon.createSandbox();9describe('deploy.deployConfig()', function() {10 // TODO: issue stubbing function in a 'then' statement11});12describe('deploy.deleteDeployment()', function() {13 // TODO: issue stubbing function in a 'then' statement14});15describe('deploy.getTriggers()', function() {16 const path = ['ScheduledDeployments', 123456];17 const scheduledDeployment = {name: 'test-deployment', path: path};18 let getEntityKeyStub;19 let getChildrenOfEntityStub;20 beforeEach(function() {21 getEntityKeyStub = sandbox.stub(datastore, 'getEntityKey');22 getChildrenOfEntityStub = sandbox.stub(datastore, 'getChildrenOfEntity');23 getEntityKeyStub.returns({path: path});24 });25 afterEach(function() {26 sandbox.restore();27 });28 it('gets successfully', function() {29 const triggers =30 [{name: 'trigger-one'}, {name: 'trigger-two'}, {name: 'trigger-three'}];31 getChildrenOfEntityStub.resolves([triggers]);32 return deploy.getTriggers(scheduledDeployment)33 .then(function(returnedTriggers) {34 expect(returnedTriggers).to.equal(triggers);35 });36 });37 it('returns a rejected promise upon error', function() {38 const error = new Error('Uh oh!');39 getChildrenOfEntityStub.rejects(error);40 return deploy.getTriggers(scheduledDeployment).catch(function(err) {41 expect(err).to.equal(error);42 });43 });44});45describe('deploy.getActiveTriggers()', function() {46 let isTriggerFormatValidStub;47 let crontabWithinIntervalStub;48 let clock;49 let parent;50 beforeEach(function() {51 clock = sinon.useFakeTimers(Date.parse('2017-08-10 00:30:00'));52 parent = {id: 11, name: 'test-deployment'};53 });54 afterEach(function() {55 sandbox.restore();56 clock.restore();57 });58 it('returns an empty array if list of Triggers is empty', function() {59 const triggers = [];60 return deploy.getActiveTriggers(triggers, parent)61 .then(function(activeTriggers) {62 assert.equal(activeTriggers.length, 0);63 });64 });65 it('rejects Promise if any Trigger has an invalid format', function() {66 const triggers = [67 {68 'name': 'test-trigger',69 'type': 'timer',70 'time': '30 10 * * *',71 'action': 'CREATE_OR_UPDATE'72 },73 {74 'name': 'invalid-trigger',75 'type': 'timer',76 'time': '30 12 * * *',77 'action': 'THIS_IS_NOT_AN_ACTION'78 }79 ];80 return deploy.getActiveTriggers(triggers, parent)81 .then(function() {82 return Promise.reject('Promise was not supposed to succeed.');83 })84 .catch(function(err) {85 expect(err).to.exist;86 });87 });88 it('returns an empty array if no Triggers are active', function() {89 parent.lastDeployed = Date.parse('2017-08-10 00:25:00');90 const triggers = [91 {92 'name': 'first-trigger',93 'type': 'timer',94 'time': '20 0 * * *',95 'action': 'CREATE_OR_UPDATE'96 },97 {98 'name': 'second-trigger',99 'type': 'timer',100 'time': '30 0 9 8 *',101 'action': 'CREATE_OR_UPDATE'102 }103 ];104 return deploy.getActiveTriggers(triggers, parent)105 .then(function(activeTriggers) {106 assert.equal(activeTriggers.length, 0);107 });108 });109 it('returns a single active Trigger', function() {110 parent.lastDeployed = Date.parse('2017-08-10 00:20:00');111 const trigger1 = {112 'name': 'create-trigger',113 'type': 'timer',114 'time': '20 0 * * *',115 'action': 'CREATE_OR_UPDATE'116 };117 const trigger2 = {118 'name': 'delete-trigger',119 'type': 'timer',120 'time': '30 0 * * *',121 'action': 'DELETE'122 };123 return deploy.getActiveTriggers([trigger1, trigger2], parent)124 .then(function(activeTriggers) {125 assert.equal(activeTriggers.length, 1);126 assert.deepEqual(127 activeTriggers[0],128 {timestamp: Date.parse('2017-08-10 00:30:00'), entity: trigger2});129 });130 });131 it('returns two active triggers', function() {132 parent.lastDeployed = Date.parse('2017-08-10 00:20:00');133 const trigger1 = {134 'name': 'create-trigger',135 'type': 'timer',136 'time': '33 0 * * *',137 'action': 'CREATE_OR_UPDATE'138 };139 const trigger2 = {140 'name': 'delete-trigger',141 'type': 'timer',142 'time': '34 0 * * *',143 'action': 'DELETE'144 };145 return deploy.getActiveTriggers([trigger1, trigger2], parent)146 .then(function(activeTriggers) {147 assert.equal(activeTriggers.length, 2);148 assert.deepEqual(activeTriggers, [149 {timestamp: Date.parse('2017-08-10 00:33:00'), entity: trigger1},150 {timestamp: Date.parse('2017-08-10 00:34:00'), entity: trigger2}151 ]);152 });153 });154});155describe('deploy.processActiveTriggers()', function() {156 const parent = {id: 11, name: 'test-deployment'};157 const timestamp = (new Date()).getTime();158 const laterTimestamp = timestamp + 1;159 let getEntityKeyStub;160 let deployConfigStub;161 let deleteDeploymentStub;162 beforeEach(function() {163 deployConfigStub = sandbox.stub(deploy, 'deployConfig');164 deleteDeploymentStub = sandbox.stub(deploy, 'deleteDeployment');165 getEntityKeyStub = sandbox.stub(datastore, 'getEntityKey');166 getEntityKeyStub.returns({id: 11});167 });168 afterEach(function() {169 sandbox.restore();170 });171 it('takes no action if list of triggers is empty', function() {172 const triggers = [];173 deploy.processActiveTriggers(triggers, parent);174 assert.equal(deployConfigStub.callCount, 0);175 assert.equal(deleteDeploymentStub.callCount, 0);176 });177 it('invokes deployment if latest active trigger is CREATE_OR_UPDATE',178 function() {179 const createTrigger = {180 timestamp: laterTimestamp,181 entity: {182 'name': 'create-trigger',183 'type': 'timer',184 'time': '34 0 * * *',185 'action': 'CREATE_OR_UPDATE'186 }187 };188 const deleteTrigger = {189 timestamp: timestamp,190 entity: {191 'name': 'delete-trigger',192 'type': 'timer',193 'time': '33 0 * * *',194 'action': 'DELETE'195 }196 };197 deploy.processActiveTriggers([createTrigger, deleteTrigger], parent);198 assert.equal(deleteDeploymentStub.callCount, 0);199 assert.equal(deployConfigStub.callCount, 1);200 assert(deployConfigStub.calledWith(createTrigger.entity));201 });202 it('invokes deployment deletion if latest active trigger is DELETE',203 function() {204 const triggers = [205 {206 timestamp: timestamp,207 entity: {208 'name': 'create-trigger',209 'type': 'timer',210 'time': '33 0 * * *',211 'action': 'CREATE_OR_UPDATE'212 }213 },214 {215 timestamp: laterTimestamp,216 entity: {217 'name': 'delete-trigger',218 'type': 'timer',219 'time': '34 0 * * *',220 'action': 'DELETE'221 }222 }223 ];224 deploy.processActiveTriggers(triggers, parent);225 assert.equal(deployConfigStub.callCount, 0);226 assert.equal(deleteDeploymentStub.callCount, 1);227 });228});229describe('deploy.crontabWithinInterval()', function() {230 const range = 10; // minutes between Cron events231 const lastDeployed = Date.parse('2017-08-10 00:00:00');232 it('make deployment now', function() {233 const time = Date.parse('2017-08-10 00:15:00');234 const crontab = '* * * * *';235 return deploy.crontabWithinInterval(time, range, crontab, lastDeployed)236 .then(function(response) {237 expect(response).to.equal(time);238 })239 });240 it('make upcoming deployment at edge of time interval', function() {241 const time = Date.parse('2017-08-10 00:15:00');242 const crontab = '10 * * * *';243 return deploy.crontabWithinInterval(time, range, crontab, lastDeployed)244 .then(function(response) {245 expect(response).to.equal(Date.parse('2017-08-10 00:10:00'));246 });247 });248 it('make previous deployment at edge of time interval', function() {249 const time = Date.parse('2017-08-10 00:35:00');250 const crontab = '30 * * * *';251 return deploy.crontabWithinInterval(time, range, crontab, lastDeployed)252 .then(function(response) {253 expect(response).to.equal(Date.parse('2017-08-10 00:30:00'));254 });255 });256 it('make a missed deployment; time is past interval end', function() {257 const time = Date.parse('2017-08-10 10:35:01');258 const crontab = '30 10 * * *';259 return deploy.crontabWithinInterval(time, range, crontab, lastDeployed)260 .then(function(response) {261 expect(response).to.equal(Date.parse('2017-08-10 10:30:00'));262 });263 });264 it('no deployment; time is past interval start', function() {265 const time = Date.parse('2017-08-10 00:24:59');266 const crontab = '30 * * * *';267 return deploy.crontabWithinInterval(time, range, crontab, lastDeployed)268 .then(function(response) {269 expect(response).to.equal(0);270 });271 });272 it('interprets fancy crontab', function() {273 const time = Date.parse('2017-08-10 03:16:00');274 const crontab = '20 3,9 10-15 Aug *';275 return deploy.crontabWithinInterval(time, range, crontab, lastDeployed)276 .then(function(response) {277 expect(response).to.equal(Date.parse('2017-08-10 03:20:00'));278 });279 });280});281describe('deploy.compareTriggers()', function() {282 const one = {283 timestamp: Date.parse('2017-08-10 00:01:00'),284 entity: {name: 'apple'}285 };286 const two = {287 timestamp: Date.parse('2017-08-10 00:02:00'),288 entity: {name: 'banana'}289 };290 const three = {291 timestamp: Date.parse('2017-08-10 00:01:00'),292 entity: {name: 'banana'}293 };294 it('prioritizes later timestamp as first parameter', function() {295 const response = deploy.compareTriggers(two, one);296 assert.equal(response, -1);297 });298 it('prioritizes later timestamp as second parameter', function() {299 const response = deploy.compareTriggers(one, two);300 assert.equal(response, 1);301 });302 it('prioritizes first parameter with later alphabetical name if timestamps equal',303 function() {304 const response = deploy.compareTriggers(three, one);305 assert.equal(response, -1);306 });307 it('prioritizes second parameter with later alphabetical name if timestamps equal',308 function() {309 const response = deploy.compareTriggers(one, three);310 assert.equal(response, 1);311 });312 it('gives equal priority to identical timestamps and names', function() {313 const response = deploy.compareTriggers(one, one);314 assert.equal(response, 0);315 });...
triggers_tests.py
Source:triggers_tests.py
...24 the_dict = {}25 sg = student_groups.StudentGroupDTO(self.COURSE_NAME, the_dict)26 self.assertEquals([], cls.copy_from_settings(sg))27 self.assertFalse(settings_name in the_dict)28 expected_triggers = self.create_triggers(cls)29 # Copy each encoded trigger in the expected_triggers into the30 # StudentGroupDTO property, so that they are distinct dict objects.31 sg.set_triggers(32 settings_name, [et.copy() for et in expected_triggers])33 self.assertTrue(settings_name in the_dict)34 self.assertItemsEqual(expected_triggers, cls.copy_from_settings(sg))35 def check_in_student_group(self, cls, settings_name):36 # in_settings() has side-effects on the supplied settings if empty.37 the_dict = {}38 sg = student_groups.StudentGroupDTO(self.COURSE_NAME, the_dict)39 self.assertEquals([], cls.in_settings(sg))40 self.assertTrue(settings_name in the_dict)41 expected_triggers = self.create_triggers(cls)42 # Copy each encoded trigger in the expected_triggers into the43 # StudentGroupDTO property, so that they are distinct dict objects.44 sg.set_triggers(45 settings_name, [et.copy() for et in expected_triggers])46 self.assertTrue(settings_name in the_dict)47 self.assertItemsEqual(expected_triggers, cls.in_settings(sg))48 def create_payload_triggers(self, cls, availabilities=None, payload=None):49 payload, expected_triggers, env = self.BASE.create_payload_triggers(50 self, cls, availabilities=availabilities, payload=payload)51 properties = {cls.SETTINGS_NAME: expected_triggers}52 # Course start/end date/time settings in the 'course' dict of the53 # Course settings map to StudentGroupDTO properties of the same name.54 for setting, when in env.get('course', {}).iteritems():55 properties[setting] = when56 expected_group = student_groups.StudentGroupDTO(57 self.COURSE_NAME, properties)58 return payload, expected_triggers, expected_group59 def check_payload_into_student_group(self, cls, settings_name):60 """Checks payload_into_settings, from_payload, set_into_settings."""61 payload, expected_triggers, expected = self.create_payload_triggers(62 cls, availabilities=cls.AVAILABILITY_VALUES)63 the_dict = {}64 sg = student_groups.StudentGroupDTO(self.COURSE_NAME, the_dict)65 cls.payload_into_settings(payload, self.course, sg)66 # Order should not matter, but the way the triggers values are67 # generated, for some trigger test classes, they are in fact in68 # a particular order (e.g. in KNOWN_MILESTONE order).69 self.assertItemsEqual(expected_triggers,70 sg.get_triggers(settings_name))71 self.assertItemsEqual(expected_triggers,72 the_dict[settings_name])73 # So, place the potentially non-ordered results in that order before74 # comparing nested structures that contain them.75 not_in_order = sg.get_triggers(settings_name)76 in_order = self.place_triggers_in_expected_order(not_in_order, cls)77 sg.set_triggers(settings_name, in_order)78 self.assertEquals(expected.dict, sg.dict)79 # Absent from payload should remove from settings. Use student_group80 # created above, since it will have properties needing removal81 # (start_date and end_date).82 cls.payload_into_settings(self.empty_form, self.course, sg)83 # Property is always obtained from StudentGroupDTO, but as empty list.84 self.assertEquals([], sg.get_triggers(settings_name))85 # Even when not actually stored as an empty list inside the DTO.86 self.assertEquals({settings_name: []}, sg.dict)87 self.assertEquals([], the_dict.get(settings_name))88class ContentOverrideTriggerTests(OverrideTriggerTestsMixin,89 triggers_tests.ContentTriggerTestBase):90 """Tests the ContentOverrideTrigger class."""91 # "Content Override Trigger Test", but UNICODE-obfuscated.92 COURSE_TITLE = u'âȫἢťеηţ Åá½»Äɼгá¿ÉÑ Ð¢á¹ÑÉ Çµá¸Ñ ΤÑṡÊ'93 COURSE_NAME = 'content_override_trigger_test'94 sg_content_ot = student_groups.ContentOverrideTrigger95 BASE = triggers_tests.ContentTriggerTestBase96 def test_name_logged_str(self):97 self.check_names(self.sg_content_ot,98 availabilities=self.sg_content_ot.AVAILABILITY_VALUES)...
config+commands.template.ts
Source:config+commands.template.ts
1/*2..######...#######..##.....##.##.....##....###....##....##.########...######.3.##....##.##.....##.###...###.###...###...##.##...###...##.##.....##.##....##4.##.......##.....##.####.####.####.####..##...##..####..##.##.....##.##......5.##.......##.....##.##.###.##.##.###.##.##.....##.##.##.##.##.....##..######.6.##.......##.....##.##.....##.##.....##.#########.##..####.##.....##.......##7.##....##.##.....##.##.....##.##.....##.##.....##.##...###.##.....##.##....##8..######...#######..##.....##.##.....##.##.....##.##....##.########...######.9 */10Config.events = {...Config.events,11 /*12 .######..######...####..13 ...##......##....##.....14 ...##......##.....####..15 ...##......##........##.16 ...##......##.....####..17 */18 [KeysTemplate.COMMAND_TTS_ON]: {19 triggers: {20 command: {}21 }22 },23 [KeysTemplate.COMMAND_TTS_OFF]: {24 triggers: {25 command: {}26 }27 },28 [KeysTemplate.COMMAND_TTS_SILENCE]: {29 triggers: {30 command: {}31 }32 },33 [KeysTemplate.COMMAND_TTS_DIE]: {34 triggers: {35 command: {}36 }37 },38 [KeysTemplate.COMMAND_TTS_NICK]: {39 triggers: {40 command: {41 permissions: {42 VIPs: true,43 subscribers: true44 }45 }46 }47 },48 [KeysTemplate.COMMAND_TTS_MUTE]: {49 triggers: {50 command: {}51 }52 },53 [KeysTemplate.COMMAND_TTS_UNMUTE]: {54 triggers: {55 command: {}56 }57 },58 [KeysTemplate.COMMAND_TTS_VOICES]: {59 triggers: {60 command: {61 permissions: {62 everyone: true63 },64 cooldown: 60 * 565 }66 },67 actions: {68 chat: 'Preview Google TTS voices here, pick a Wavenet (mandatory) voice and use the name with the "Set Your Voice" reward: https://cloud.google.com/text-to-speech/docs/voices'69 }70 },71 /*72 ..####...##..##...####...######.73 .##..##..##..##..##..##....##...74 .##......######..######....##...75 .##..##..##..##..##..##....##...76 ..####...##..##..##..##....##...77 */78 [KeysTemplate.COMMAND_CHAT]: {79 triggers: {80 command: {81 permissions: {82 VIPs: true83 }84 }85 }86 },87 [KeysTemplate.COMMAND_CHAT_ON]: {88 triggers: {89 command: {}90 }91 },92 [KeysTemplate.COMMAND_CHAT_OFF]: {93 triggers: {94 command: {}95 }96 },97 [KeysTemplate.COMMAND_PING_ON]: {98 triggers: {99 command: {}100 }101 },102 [KeysTemplate.COMMAND_PING_OFF]: {103 triggers: {104 command: {}105 }106 },107 [KeysTemplate.COMMAND_QUOTE]: {108 triggers: {109 command: {}110 }111 },112 /*113 .##.......####....####..114 .##......##..##..##.....115 .##......##..##..##.###.116 .##......##..##..##..##.117 .######...####....####..118 */119 [KeysTemplate.COMMAND_LOG_ON]: {120 triggers: {121 command: {122 permissions: {123 moderators: false124 }125 }126 }127 },128 [KeysTemplate.COMMAND_LOG_OFF]: {129 triggers: {130 command: {131 permissions: {132 moderators: false133 }134 }135 }136 },137 /*138 ..####....####....####...##......######.139 .##......##..##..##..##..##......##.....140 ..####...##......######..##......####...141 .....##..##..##..##..##..##......##.....142 ..####....####...##..##..######..######.143 */144 [KeysTemplate.COMMAND_SCALE]: {145 triggers: {146 command: {}147 }148 },149 /*150 ..####...######..######...####...##...##..##..##..#####..151 .##........##....##......##..##..###.###..##..##..##..##.152 ..####.....##....####....######..##.#.##..##..##..#####..153 .....##....##....##......##..##..##...##...####...##..##.154 ..####.....##....######..##..##..##...##....##....##..##.155 */156 [KeysTemplate.COMMAND_BRIGHTNESS]: {157 triggers: {158 command: {159 permissions: {160 moderators: false161 }162 }163 }164 },165 [KeysTemplate.COMMAND_REFRESHRATE]: {166 triggers: {167 command: {168 permissions: {169 moderators: false170 }171 }172 }173 },174 [KeysTemplate.COMMAND_VRVIEWEYE]: {175 triggers: {176 command: {177 permissions: {178 moderators: false179 }180 }181 }182 },183 /*184 .#####...######...####...######..######...####...##..##...####...#####...##..##.185 .##..##....##....##..##....##......##....##..##..###.##..##..##..##..##...####..186 .##..##....##....##........##......##....##..##..##.###..######..#####.....##...187 .##..##....##....##..##....##......##....##..##..##..##..##..##..##..##....##...188 .#####...######...####.....##....######...####...##..##..##..##..##..##....##...189 */190 [KeysTemplate.COMMAND_DICTIONARY]: {191 triggers: {192 command: {}193 }194 },195 /*196 .#####...######..##...##...####...#####...#####....####..197 .##..##..##......##...##..##..##..##..##..##..##..##.....198 .#####...####....##.#.##..######..#####...##..##...####..199 .##..##..##......#######..##..##..##..##..##..##......##.200 .##..##..######...##.##...##..##..##..##..#####....####..201 */202 [KeysTemplate.COMMAND_UPDATEREWARDS]: {203 triggers: {204 command: {205 permissions: {206 moderators: false207 }208 }209 }210 },211 [KeysTemplate.COMMAND_GAMEREWARDS_ON]: {212 triggers: {213 command: {}214 }215 },216 [KeysTemplate.COMMAND_GAMEREWARDS_OFF]: {217 triggers: {218 command: {}219 }220 },221 [KeysTemplate.COMMAND_REFUND_REDEMPTION]: {222 triggers: {223 command: {224 cooldown: 30225 }226 }227 },228 [KeysTemplate.COMMAND_CLEAR_REDEMPTIONS]: {229 triggers: {230 command: {231 permissions: {232 moderators: false233 },234 cooldown: 60235 }236 }237 },238 [KeysTemplate.COMMAND_RESET_INCREWARD]: {239 triggers: {240 command: {241 permissions: {242 moderators: false243 },244 cooldown: 20245 }246 }247 },248 /*249 ..####...##..##...####...######..######..##...##.250 .##.......####...##........##....##......###.###.251 ..####.....##.....####.....##....####....##.#.##.252 .....##....##........##....##....##......##...##.253 ..####.....##.....####.....##....######..##...##.254 */ 255 [KeysTemplate.COMMAND_RELOADWIDGET]: {256 triggers: {257 command: {258 permissions: {259 moderators: false260 }261 }262 }263 },264 [KeysTemplate.COMMAND_CHANNELTROPHY_STATS]: {265 triggers: {266 command: {267 permissions: {268 moderators: false269 }270 }271 }272 },273 [KeysTemplate.COMMAND_CLIPS]: {274 triggers: {275 command: {276 permissions: {277 moderators: false278 }279 }280 }281 },282 [KeysTemplate.COMMAND_GAMERESET]: {283 triggers: {284 command: {285 permissions: {286 moderators: false287 }288 }289 }290 },291 [KeysTemplate.COMMAND_RAID]: {292 triggers: {293 command: {}294 }295 },296 [KeysTemplate.COMMAND_UNRAID]: {297 triggers: {298 command: {}299 }300 },301 /*302 .#####...##..##..#####...##......######...####..303 .##..##..##..##..##..##..##........##....##..##.304 .#####...##..##..#####...##........##....##.....305 .##......##..##..##..##..##........##....##..##.306 .##.......####...#####...######..######...####..307 */308 [KeysTemplate.COMMAND_GAME]: {309 triggers: {310 command: {311 permissions: {312 everyone: true313 },314 cooldown: 3*60315 }316 },317 actions: {318 sign: {319 title: 'Current Game',320 image: '%gameBanner',321 subtitle: '%gameName\n%gamePrice',322 durationMs: 10000323 },324 chat: 'Game: %gameName - Released: %gameRelease - Price: %gamePrice - Link: %gameLink'325 }326 },327 /*328 .######..##..##...####...##...##..#####...##......######...####..329 .##.......####...##..##..###.###..##..##..##......##......##.....330 .####......##....######..##.#.##..#####...##......####.....####..331 .##.......####...##..##..##...##..##......##......##..........##.332 .######..##..##..##..##..##...##..##......######..######...####..333 */334 [KeysTemplate.COMMAND_SAY]: { // Announces something with the TTS335 triggers: {336 command: {}337 },338 actions: {339 speech: {340 entries: '%userInput'341 }342 }343 },344 [KeysTemplate.COMMAND_LABEL]: { // Writes a label to the disk that can be used as a source345 triggers: {346 command: {}347 },348 actions: {349 speech: {350 entries: 'Label set to "%userInput"'351 },352 label: "your_label_in_settings.txt"353 }354 },355 [KeysTemplate.COMMAND_TODO]: { // Puts a post in Discord using the Discord webhook with the same key356 triggers: {357 command: {}358 },359 actions: {360 speech: {361 entries: 'To do list appended with: %userInput'362 },363 discord: '-> %userInput'364 }365 },366 [KeysTemplate.COMMAND_END_STREAM]: {367 triggers: {368 command: {369 permissions: {370 moderators: false371 }372 }373 },374 actions: {375 speech: {376 entries: 'Running stream end tasks'377 },378 commands: { 379 entries: [380 KeysTemplate.COMMAND_CHANNELTROPHY_STATS,381 KeysTemplate.COMMAND_CLIPS,382 KeysTemplate.COMMAND_CLEAR_REDEMPTIONS,383 KeysTemplate.COMMAND_RESET_INCREWARD384 ],385 interval: 20386 }387 }388 }...
triggers.js
Source:triggers.js
1Tinytest.addAsync(2'Triggers - runTriggers - run all and after',3function(test, done) {4 var store = [];5 var triggers = MakeTriggers(2, store);6 Triggers.runTriggers(triggers, null, null, function() {7 test.equal(store, [0, 1]);8 done();9 });10});11Tinytest.addAsync(12'Triggers - runTriggers - redirect with url',13function(test, done) {14 var store = [];15 var url = "http://google.com";16 var triggers = MakeTriggers(2, store);17 triggers.splice(1, 0, function(context, redirect) {18 redirect(url); 19 });20 Triggers.runTriggers(triggers, null, function(u) {21 test.equal(store, [0]);22 test.equal(u, url);23 done();24 }, null);25});26Tinytest.addAsync(27'Triggers - runTriggers - redirect without url',28function(test, done) {29 var store = [];30 var url = "http://google.com";31 var triggers = MakeTriggers(2, store);32 triggers.splice(1, 0, function(context, redirect) {33 try {34 redirect(); 35 } catch(ex) {36 test.isTrue(/requires an URL/.test(ex.message));37 test.equal(store, [0]);38 done();39 }40 });41 Triggers.runTriggers(triggers, null, null, null);42});43Tinytest.addAsync(44'Triggers - runTriggers - redirect in a different event loop',45function(test, done) {46 var store = [];47 var url = "http://google.com";48 var triggers = MakeTriggers(2, store);49 var doneCalled = false;50 triggers.splice(1, 0, function(context, redirect) {51 setTimeout(function() {52 try {53 redirect(url); 54 } catch(ex) {55 test.isTrue(/sync/.test(ex.message));56 test.equal(store, [0, 1]);57 test.isTrue(doneCalled);58 done();59 }60 }, 0);61 });62 Triggers.runTriggers(triggers, null, null, function() {63 doneCalled = true;64 });65});66Tinytest.addAsync(67'Triggers - runTriggers - redirect called multiple times',68function(test, done) {69 var store = [];70 var url = "http://google.com";71 var triggers = MakeTriggers(2, store);72 var redirectCalled = false;73 triggers.splice(1, 0, function(context, redirect) {74 redirect(url); 75 try {76 redirect(url);77 } catch(ex) {78 test.isTrue(/already redirected/.test(ex.message));79 test.equal(store, [0]);80 test.isTrue(redirectCalled);81 done();82 }83 });84 Triggers.runTriggers(triggers, null, function() {85 redirectCalled = true;86 }, null);87});88Tinytest.addAsync(89'Triggers - runTriggers - stop callback',90function(test, done) {91 var store = [];92 var triggers = MakeTriggers(2, store);93 triggers.splice(1, 0, function(context, redirect, stop) {94 stop();95 });96 Triggers.runTriggers(triggers, null, null, function() {97 store.push(2);98 });99 test.equal(store, [0]);100 done();101});102Tinytest.addAsync(103'Triggers - runTriggers - get context',104function(test, done) {105 var context = {};106 var trigger = function(c) {107 test.equal(c, context);108 done();109 };110 Triggers.runTriggers([trigger], context, function() {}, function() {});111});112Tinytest.addAsync(113'Triggers - createRouteBoundTriggers - matching trigger',114function(test, done) {115 var context = {route: {name: "abc"}};116 var redirect = function() {};117 var trigger = function(c, r) {118 test.equal(c, context);119 test.equal(r, redirect);120 done();121 };122 var triggers = Triggers.createRouteBoundTriggers([trigger], ["abc"]);123 triggers[0](context, redirect);124});125Tinytest.addAsync(126'Triggers - createRouteBoundTriggers - multiple matching triggers',127function(test, done) {128 var context = {route: {name: "abc"}};129 var redirect = function() {};130 var doneCount = 0;131 var trigger = function(c, r) {132 test.equal(c, context);133 test.equal(r, redirect);134 doneCount++;135 };136 var triggers = Triggers.createRouteBoundTriggers([trigger, trigger], ["abc"]);137 triggers[0](context, redirect);138 triggers[1](context, redirect);139 test.equal(doneCount, 2);140 done();141});142Tinytest.addAsync(143'Triggers - createRouteBoundTriggers - no matching trigger',144function(test, done) {145 var context = {route: {name: "some-other-route"}};146 var redirect = function() {};147 var doneCount = 0;148 var trigger = function(c, r) {149 test.equal(c, context);150 test.equal(r, redirect);151 doneCount++;152 };153 var triggers = Triggers.createRouteBoundTriggers([trigger], ["abc"]);154 triggers[0](context, redirect);155 test.equal(doneCount, 0);156 done();157});158Tinytest.addAsync(159'Triggers - createRouteBoundTriggers - negate logic',160function(test, done) {161 var context = {route: {name: "some-other-route"}};162 var redirect = function() {};163 var doneCount = 0;164 var trigger = function(c, r) {165 test.equal(c, context);166 test.equal(r, redirect);167 doneCount++;168 };169 var triggers = Triggers.createRouteBoundTriggers([trigger], ["abc"], true);170 triggers[0](context, redirect);171 test.equal(doneCount, 1);172 done();173});174Tinytest.addAsync(175'Triggers - applyFilters - no filters',176function(test, done) {177 var original = [];178 test.equal(Triggers.applyFilters(original), original);179 done();180});181Tinytest.addAsync(182'Triggers - applyFilters - single trigger to array',183function(test, done) {184 var original = function() {};185 test.equal(Triggers.applyFilters(original)[0], original);186 done();187});188Tinytest.addAsync(189'Triggers - applyFilters - only and except both',190function(test, done) {191 var original = [];192 try {193 Triggers.applyFilters(original, {only: [], except: []});194 } catch(ex) {195 test.isTrue(/only and except/.test(ex.message));196 done();197 }198});199Tinytest.addAsync(200'Triggers - applyFilters - only is not an array',201function(test, done) {202 var original = [];203 try {204 Triggers.applyFilters(original, {only: "name"});205 } catch(ex) {206 test.isTrue(/to be an array/.test(ex.message));207 done();208 }209});210Tinytest.addAsync(211'Triggers - applyFilters - except is not an array',212function(test, done) {213 var original = [];214 try {215 Triggers.applyFilters(original, {except: "name"});216 } catch(ex) {217 test.isTrue(/to be an array/.test(ex.message));218 done();219 }220});221Tinytest.addAsync(222'Triggers - applyFilters - unsupported filter',223function(test, done) {224 var original = [];225 try {226 Triggers.applyFilters(original, {wowFilter: []});227 } catch(ex) {228 test.isTrue(/not supported/.test(ex.message));229 done();230 }231});232Tinytest.addAsync(233'Triggers - applyFilters - just only filter',234function(test, done) {235 var bounded = Triggers.applyFilters(done, {only: ["abc"]});236 bounded[0]({route: {name: "abc"}});237});238Tinytest.addAsync(239'Triggers - applyFilters - just except filter',240function(test, done) {241 var bounded = Triggers.applyFilters(done, {except: ["abc"]});242 bounded[0]({route: {name: "some-other"}});243});244function MakeTriggers(count, store) {245 var triggers = [];246 function addTrigger(no) {247 triggers.push(function() {248 store.push(no);249 });250 }251 for(var lc=0; lc<count; lc++) {252 addTrigger(lc);253 }254 return triggers;...
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!!