How to use postJSON method in mountebank

Best JavaScript code snippet using mountebank

model_tags_spec.js

Source:model_tags_spec.js Github

copy

Full Screen

1/*globals describe, before, beforeEach, afterEach, it */2/*jshint expr:true*/3var testUtils = require('../../utils'),4 should = require('should'),5 sinon = require('sinon'),6 Promise = require('bluebird'),7 _ = require('lodash'),8 // Stuff we are testing9 ModelsTag = require('../../../server/models/tag'),10 ModelsPost = require('../../../server/models/post'),11 events = require('../../../server/events'),12 context = testUtils.context.admin,13 TagModel,14 PostModel,15 sandbox = sinon.sandbox.create();16describe('Tag Model', function () {17 var eventSpy;18 // Keep the DB clean19 before(testUtils.teardown);20 afterEach(testUtils.teardown);21 beforeEach(testUtils.setup());22 afterEach(function () {23 sandbox.restore();24 });25 beforeEach(function () {26 eventSpy = sandbox.spy(events, 'emit');27 });28 before(function () {29 TagModel = ModelsTag.Tag;30 PostModel = ModelsPost.Post;31 should.exist(TagModel);32 should.exist(PostModel);33 });34 it('uses Date objects for dateTime fields', function (done) {35 TagModel.add(testUtils.DataGenerator.forModel.tags[0], context).then(function (tag) {36 return TagModel.findOne({id: tag.id});37 }).then(function (tag) {38 should.exist(tag);39 tag.get('created_at').should.be.an.instanceof(Date);40 done();41 }).catch(done);42 });43 it('returns count.posts if include count.posts', function (done) {44 testUtils.fixtures.insertPosts().then(function () {45 TagModel.findOne({slug: 'kitchen-sink'}, {include: 'count.posts'}).then(function (tag) {46 should.exist(tag);47 tag.toJSON().count.posts.should.equal(2);48 done();49 }).catch(done);50 });51 });52 describe('findPage', function () {53 beforeEach(function (done) {54 testUtils.fixtures.insertPosts().then(function () {55 done();56 }).catch(done);57 });58 it('with limit all', function (done) {59 TagModel.findPage({limit: 'all'}).then(function (results) {60 results.meta.pagination.page.should.equal(1);61 results.meta.pagination.limit.should.equal('all');62 results.meta.pagination.pages.should.equal(1);63 results.tags.length.should.equal(5);64 done();65 }).catch(done);66 });67 it('with include count.posts', function (done) {68 TagModel.findPage({limit: 'all', include: 'count.posts'}).then(function (results) {69 results.meta.pagination.page.should.equal(1);70 results.meta.pagination.limit.should.equal('all');71 results.meta.pagination.pages.should.equal(1);72 results.tags.length.should.equal(5);73 should.exist(results.tags[0].count.posts);74 done();75 }).catch(done);76 });77 });78 describe('findOne', function () {79 beforeEach(function (done) {80 testUtils.fixtures.insertPosts().then(function () {81 done();82 }).catch(done);83 });84 it('with slug', function (done) {85 var firstTag;86 TagModel.findPage().then(function (results) {87 should.exist(results);88 should.exist(results.tags);89 results.tags.length.should.be.above(0);90 firstTag = results.tags[0];91 return TagModel.findOne({slug: firstTag.slug});92 }).then(function (found) {93 should.exist(found);94 done();95 }).catch(done);96 });97 });98 describe('Post tag handling, post with NO tags', function () {99 var postJSON,100 tagJSON,101 editOptions,102 createTag = testUtils.DataGenerator.forKnex.createTag;103 beforeEach(function (done) {104 tagJSON = [];105 var post = testUtils.DataGenerator.forModel.posts[0],106 extraTag1 = createTag({name: 'existing tag a'}),107 extraTag2 = createTag({name: 'existing-tag-b'}),108 extraTag3 = createTag({name: 'existing_tag_c'});109 return Promise.props({110 post: PostModel.add(post, _.extend({}, context, {withRelated: ['tags']})),111 tag1: TagModel.add(extraTag1, context),112 tag2: TagModel.add(extraTag2, context),113 tag3: TagModel.add(extraTag3, context)114 }).then(function (result) {115 postJSON = result.post.toJSON({include: ['tags']});116 tagJSON.push(result.tag1.toJSON());117 tagJSON.push(result.tag2.toJSON());118 tagJSON.push(result.tag3.toJSON());119 editOptions = _.extend({}, context, {id: postJSON.id, withRelated: ['tags']});120 done();121 }).catch(done);122 });123 it('should create the test data correctly', function () {124 // creates two test tags125 should.exist(tagJSON);126 tagJSON.should.be.an.Array.with.lengthOf(3);127 tagJSON.should.have.enumerable(0).with.property('name', 'existing tag a');128 tagJSON.should.have.enumerable(1).with.property('name', 'existing-tag-b');129 tagJSON.should.have.enumerable(2).with.property('name', 'existing_tag_c');130 // creates a test post with no tags131 should.exist(postJSON);132 postJSON.title.should.eql('HTML Ipsum');133 should.exist(postJSON.tags);134 });135 describe('Adding brand new tags', function () {136 it('can add a single tag', function (done) {137 var newJSON = _.cloneDeep(postJSON);138 // Add a single tag to the end of the array139 newJSON.tags.push(createTag({name: 'tag1'}));140 // Edit the post141 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {142 updatedPost = updatedPost.toJSON({include: ['tags']});143 updatedPost.tags.should.have.lengthOf(1);144 updatedPost.tags.should.have.enumerable(0).with.property('name', 'tag1');145 done();146 }).catch(done);147 });148 it('can add multiple tags', function (done) {149 var newJSON = _.cloneDeep(postJSON);150 // Add a bunch of tags to the end of the array151 newJSON.tags.push(createTag({name: 'tag1'}));152 newJSON.tags.push(createTag({name: 'tag2'}));153 newJSON.tags.push(createTag({name: 'tag3'}));154 newJSON.tags.push(createTag({name: 'tag4'}));155 newJSON.tags.push(createTag({name: 'tag5'}));156 // Edit the post157 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {158 updatedPost = updatedPost.toJSON({include: ['tags']});159 updatedPost.tags.should.have.lengthOf(5);160 updatedPost.tags.should.have.enumerable(0).with.property('name', 'tag1');161 updatedPost.tags.should.have.enumerable(1).with.property('name', 'tag2');162 updatedPost.tags.should.have.enumerable(2).with.property('name', 'tag3');163 updatedPost.tags.should.have.enumerable(3).with.property('name', 'tag4');164 updatedPost.tags.should.have.enumerable(4).with.property('name', 'tag5');165 done();166 }).catch(done);167 });168 it('can add multiple tags with conflicting slugs', function (done) {169 var newJSON = _.cloneDeep(postJSON);170 // Add conflicting tags to the end of the array171 newJSON.tags.push({name: 'C'});172 newJSON.tags.push({name: 'C++'});173 newJSON.tags.push({name: 'C#'});174 // Edit the post175 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {176 updatedPost = updatedPost.toJSON({include: ['tags']});177 updatedPost.tags.should.have.lengthOf(3);178 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'C', slug: 'c'});179 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'C++', slug: 'c-2'});180 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'C#', slug: 'c-3'});181 done();182 }).catch(done);183 });184 });185 describe('Adding pre-existing tags', function () {186 it('can add a single tag', function (done) {187 var newJSON = _.cloneDeep(postJSON);188 // Add a single pre-existing tag189 newJSON.tags.push(tagJSON[0]);190 // Edit the post191 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {192 updatedPost = updatedPost.toJSON({include: ['tags']});193 updatedPost.tags.should.have.lengthOf(1);194 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'existing tag a', id: tagJSON[0].id});195 done();196 }).catch(done);197 });198 it('can add multiple tags', function (done) {199 var newJSON = _.cloneDeep(postJSON);200 // Add many preexisting tags201 newJSON.tags.push(tagJSON[0]);202 newJSON.tags.push(tagJSON[1]);203 newJSON.tags.push(tagJSON[2]);204 // Edit the post205 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {206 updatedPost = updatedPost.toJSON({include: ['tags']});207 updatedPost.tags.should.have.lengthOf(3);208 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'existing tag a', id: tagJSON[0].id});209 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'existing-tag-b', id: tagJSON[1].id});210 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'existing_tag_c', id: tagJSON[2].id});211 done();212 }).catch(done);213 });214 it('can add multiple tags in wrong order', function (done) {215 var newJSON = _.cloneDeep(postJSON);216 // Add tags to the array217 newJSON.tags.push(tagJSON[2]);218 newJSON.tags.push(tagJSON[0]);219 newJSON.tags.push(tagJSON[1]);220 // Edit the post221 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {222 updatedPost = updatedPost.toJSON({include: ['tags']});223 updatedPost.tags.should.have.lengthOf(3);224 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'existing_tag_c', id: tagJSON[2].id});225 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'existing tag a', id: tagJSON[0].id});226 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'existing-tag-b', id: tagJSON[1].id});227 done();228 }).catch(done);229 });230 });231 describe('Adding combinations', function () {232 it('can add a combination of new and pre-existing tags', function (done) {233 var newJSON = _.cloneDeep(postJSON);234 // Add a bunch of new and existing tags to the array235 newJSON.tags.push({name: 'tag1'});236 newJSON.tags.push({name: 'existing tag a'});237 newJSON.tags.push({name: 'tag3'});238 newJSON.tags.push({name: 'existing-tag-b'});239 newJSON.tags.push({name: 'tag5'});240 newJSON.tags.push({name: 'existing_tag_c'});241 // Edit the post242 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {243 updatedPost = updatedPost.toJSON({include: ['tags']});244 updatedPost.tags.should.have.lengthOf(6);245 updatedPost.tags.should.have.enumerable(0).with.property('name', 'tag1');246 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'existing tag a', id: tagJSON[0].id});247 updatedPost.tags.should.have.enumerable(2).with.property('name', 'tag3');248 updatedPost.tags.should.have.enumerable(3).with.properties({name: 'existing-tag-b', id: tagJSON[1].id});249 updatedPost.tags.should.have.enumerable(4).with.property('name', 'tag5');250 updatedPost.tags.should.have.enumerable(5).with.properties({name: 'existing_tag_c', id: tagJSON[2].id});251 done();252 }).catch(done);253 });254 });255 });256 describe('Post tag handling, post with tags', function () {257 var postJSON,258 tagJSON,259 editOptions,260 createTag = testUtils.DataGenerator.forKnex.createTag;261 beforeEach(function (done) {262 tagJSON = [];263 var post = testUtils.DataGenerator.forModel.posts[0],264 postTags = [265 createTag({name: 'tag1'}),266 createTag({name: 'tag2'}),267 createTag({name: 'tag3'})268 ],269 extraTags = [270 createTag({name: 'existing tag a'}),271 createTag({name: 'existing-tag-b'}),272 createTag({name: 'existing_tag_c'})273 ];274 post.tags = postTags;275 return Promise.props({276 post: PostModel.add(post, _.extend({}, context, {withRelated: ['tags']})),277 tag1: TagModel.add(extraTags[0], context),278 tag2: TagModel.add(extraTags[1], context),279 tag3: TagModel.add(extraTags[2], context)280 }).then(function (result) {281 postJSON = result.post.toJSON({include: ['tags']});282 tagJSON.push(result.tag1.toJSON());283 tagJSON.push(result.tag2.toJSON());284 tagJSON.push(result.tag3.toJSON());285 editOptions = _.extend({}, context, {id: postJSON.id, withRelated: ['tags']});286 done();287 });288 });289 it('should create the test data correctly', function () {290 // creates a test tag291 should.exist(tagJSON);292 tagJSON.should.be.an.Array.with.lengthOf(3);293 tagJSON.should.have.enumerable(0).with.property('name', 'existing tag a');294 tagJSON.should.have.enumerable(1).with.property('name', 'existing-tag-b');295 tagJSON.should.have.enumerable(2).with.property('name', 'existing_tag_c');296 // creates a test post with an array of tags in the correct order297 should.exist(postJSON);298 postJSON.title.should.eql('HTML Ipsum');299 should.exist(postJSON.tags);300 postJSON.tags.should.be.an.Array.and.have.lengthOf(3);301 postJSON.tags.should.have.enumerable(0).with.property('name', 'tag1');302 postJSON.tags.should.have.enumerable(1).with.property('name', 'tag2');303 postJSON.tags.should.have.enumerable(2).with.property('name', 'tag3');304 });305 describe('Adding brand new tags', function () {306 it('can add a single tag to the end of the tags array', function (done) {307 var newJSON = _.cloneDeep(postJSON);308 // Add a single tag to the end of the array309 newJSON.tags.push(createTag({name: 'tag4'}));310 // Edit the post311 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {312 updatedPost = updatedPost.toJSON({include: ['tags']});313 updatedPost.tags.should.have.lengthOf(4);314 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag1', id: postJSON.tags[0].id});315 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag2', id: postJSON.tags[1].id});316 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag3', id: postJSON.tags[2].id});317 updatedPost.tags.should.have.enumerable(3).with.property('name', 'tag4');318 done();319 }).catch(done);320 });321 it('can add a single tag to the beginning of the tags array', function (done) {322 var newJSON = _.cloneDeep(postJSON);323 // Add a single tag to the beginning of the array324 newJSON.tags = [createTag({name: 'tag4'})].concat(postJSON.tags);325 // Edit the post326 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {327 updatedPost = updatedPost.toJSON({include: ['tags']});328 updatedPost.tags.should.have.lengthOf(4);329 updatedPost.tags.should.have.enumerable(0).with.property('name', 'tag4');330 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag1', id: postJSON.tags[0].id});331 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag2', id: postJSON.tags[1].id});332 updatedPost.tags.should.have.enumerable(3).with.properties({name: 'tag3', id: postJSON.tags[2].id});333 done();334 }).catch(done);335 });336 });337 describe('Adding pre-existing tags', function () {338 it('can add a single tag to the end of the tags array', function (done) {339 var newJSON = _.cloneDeep(postJSON);340 // Add a single pre-existing tag to the end of the array341 newJSON.tags.push(tagJSON[0]);342 // Edit the post343 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {344 updatedPost = updatedPost.toJSON({include: ['tags']});345 updatedPost.tags.should.have.lengthOf(4);346 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag1', id: postJSON.tags[0].id});347 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag2', id: postJSON.tags[1].id});348 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag3', id: postJSON.tags[2].id});349 updatedPost.tags.should.have.enumerable(3).with.properties({name: 'existing tag a', id: tagJSON[0].id});350 done();351 }).catch(done);352 });353 it('can add a single tag to the beginning of the tags array', function (done) {354 var newJSON = _.cloneDeep(postJSON);355 // Add an existing tag to the beginning of the array356 newJSON.tags = [tagJSON[0]].concat(postJSON.tags);357 // Edit the post358 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {359 updatedPost = updatedPost.toJSON({include: ['tags']});360 updatedPost.tags.should.have.lengthOf(4);361 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'existing tag a', id: tagJSON[0].id});362 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag1', id: postJSON.tags[0].id});363 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag2', id: postJSON.tags[1].id});364 updatedPost.tags.should.have.enumerable(3).with.properties({name: 'tag3', id: postJSON.tags[2].id});365 done();366 }).catch(done);367 });368 it('can add a single tag to the middle of the tags array', function (done) {369 var newJSON = _.cloneDeep(postJSON);370 // Add a single pre-existing tag to the middle of the array371 newJSON.tags = postJSON.tags.slice(0, 1).concat([tagJSON[0]]).concat(postJSON.tags.slice(1));372 // Edit the post373 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {374 updatedPost = updatedPost.toJSON({include: ['tags']});375 updatedPost.tags.should.have.lengthOf(4);376 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag1', id: postJSON.tags[0].id});377 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'existing tag a', id: tagJSON[0].id});378 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag2', id: postJSON.tags[1].id});379 updatedPost.tags.should.have.enumerable(3).with.properties({name: 'tag3', id: postJSON.tags[2].id});380 done();381 }).catch(done);382 });383 });384 describe('Removing tags', function () {385 it('can remove a single tag from the end of the tags array', function (done) {386 var newJSON = _.cloneDeep(postJSON);387 // Remove a single tag from the end of the array388 newJSON.tags = postJSON.tags.slice(0, -1);389 // Edit the post390 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {391 updatedPost = updatedPost.toJSON({include: ['tags']});392 updatedPost.tags.should.have.lengthOf(2);393 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag1', id: postJSON.tags[0].id});394 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag2', id: postJSON.tags[1].id});395 done();396 }).catch(done);397 });398 it('can remove a single tag from the beginning of the tags array', function (done) {399 var newJSON = _.cloneDeep(postJSON);400 // Remove a single tag from the beginning of the array401 newJSON.tags = postJSON.tags.slice(1);402 // Edit the post403 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {404 updatedPost = updatedPost.toJSON({include: ['tags']});405 updatedPost.tags.should.have.lengthOf(2);406 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag2', id: postJSON.tags[1].id});407 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag3', id: postJSON.tags[2].id});408 done();409 }).catch(done);410 });411 it('can remove all tags', function (done) {412 var newJSON = _.cloneDeep(postJSON);413 // Remove all the tags414 newJSON.tags = [];415 // Edit the post416 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {417 updatedPost = updatedPost.toJSON({include: ['tags']});418 updatedPost.tags.should.have.lengthOf(0);419 done();420 }).catch(done);421 });422 });423 describe('Reordering tags', function () {424 it('can reorder the first tag to be the last', function (done) {425 var newJSON = _.cloneDeep(postJSON),426 firstTag = [postJSON.tags[0]];427 // Reorder the tags, so that the first tag is moved to the end428 newJSON.tags = postJSON.tags.slice(1).concat(firstTag);429 // Edit the post430 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {431 updatedPost = updatedPost.toJSON({include: ['tags']});432 updatedPost.tags.should.have.lengthOf(3);433 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag2', id: postJSON.tags[1].id});434 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag3', id: postJSON.tags[2].id});435 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag1', id: postJSON.tags[0].id});436 done();437 }).catch(done);438 });439 it('can reorder the last tag to be the first', function (done) {440 var newJSON = _.cloneDeep(postJSON),441 lastTag = [postJSON.tags[2]];442 // Reorder the tags, so that the last tag is moved to the beginning443 newJSON.tags = lastTag.concat(postJSON.tags.slice(0, -1));444 // Edit the post445 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {446 updatedPost = updatedPost.toJSON({include: ['tags']});447 updatedPost.tags.should.have.lengthOf(3);448 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag3', id: postJSON.tags[2].id});449 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag1', id: postJSON.tags[0].id});450 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag2', id: postJSON.tags[1].id});451 done();452 }).catch(done);453 });454 });455 describe('Combination updates', function () {456 it('can add a combination of new and pre-existing tags', function (done) {457 var newJSON = _.cloneDeep(postJSON);458 // Push a bunch of new and existing tags to the end of the array459 newJSON.tags.push({name: 'tag4'});460 newJSON.tags.push({name: 'existing tag a'});461 newJSON.tags.push({name: 'tag5'});462 newJSON.tags.push({name: 'existing-tag-b'});463 newJSON.tags.push({name: 'bob'});464 newJSON.tags.push({name: 'existing_tag_c'});465 // Edit the post466 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {467 updatedPost = updatedPost.toJSON({include: ['tags']});468 updatedPost.tags.should.have.lengthOf(9);469 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag1', id: postJSON.tags[0].id});470 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag2', id: postJSON.tags[1].id});471 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag3', id: postJSON.tags[2].id});472 updatedPost.tags.should.have.enumerable(3).with.property('name', 'tag4');473 updatedPost.tags.should.have.enumerable(4).with.properties({name: 'existing tag a', id: tagJSON[0].id});474 updatedPost.tags.should.have.enumerable(5).with.property('name', 'tag5');475 updatedPost.tags.should.have.enumerable(6).with.properties({name: 'existing-tag-b', id: tagJSON[1].id});476 updatedPost.tags.should.have.enumerable(7).with.property('name', 'bob');477 updatedPost.tags.should.have.enumerable(8).with.properties({name: 'existing_tag_c', id: tagJSON[2].id});478 done();479 }).catch(done);480 });481 it('can reorder the first tag to be the last and add a tag to the beginning', function (done) {482 var newJSON = _.cloneDeep(postJSON),483 firstTag = [postJSON.tags[0]];484 // Add a new tag to the beginning, and move the original first tag to the end485 newJSON.tags = [tagJSON[0]].concat(postJSON.tags.slice(1)).concat(firstTag);486 // Edit the post487 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {488 updatedPost = updatedPost.toJSON({include: ['tags']});489 updatedPost.tags.should.have.lengthOf(4);490 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'existing tag a', id: tagJSON[0].id});491 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag2', id: postJSON.tags[1].id});492 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag3', id: postJSON.tags[2].id});493 updatedPost.tags.should.have.enumerable(3).with.properties({name: 'tag1', id: postJSON.tags[0].id});494 done();495 }).catch(done);496 });497 it('can reorder the first tag to be the last, remove the original last tag & add a tag to the beginning', function (done) {498 var newJSON = _.cloneDeep(postJSON),499 firstTag = [newJSON.tags[0]];500 // And an existing tag to the beginning of the array, move the original first tag to the end and remove the original last tag501 newJSON.tags = [tagJSON[0]].concat(newJSON.tags.slice(1, -1)).concat(firstTag);502 // Edit the post503 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {504 updatedPost = updatedPost.toJSON({include: ['tags']});505 updatedPost.tags.should.have.lengthOf(3);506 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'existing tag a', id: tagJSON[0].id});507 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'tag2', id: postJSON.tags[1].id});508 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag1', id: postJSON.tags[0].id});509 done();510 }).catch(done);511 });512 it('can reorder original tags, remove one, and add new and existing tags', function (done) {513 var newJSON = _.cloneDeep(postJSON),514 firstTag = [newJSON.tags[0]];515 // Reorder original 3 so that first is at the end516 newJSON.tags = newJSON.tags.slice(1).concat(firstTag);517 // add an existing tag in the middle518 newJSON.tags = newJSON.tags.slice(0, 1).concat({name: 'existing-tag-b'}).concat(newJSON.tags.slice(1));519 // add a brand new tag in the middle520 newJSON.tags = newJSON.tags.slice(0, 3).concat({name: 'betty'}).concat(newJSON.tags.slice(3));521 // Add some more tags to the end522 newJSON.tags.push({name: 'bob'});523 newJSON.tags.push({name: 'existing tag a'});524 // Edit the post525 return PostModel.edit(newJSON, editOptions).then(function (updatedPost) {526 updatedPost = updatedPost.toJSON({include: ['tags']});527 updatedPost.tags.should.have.lengthOf(7);528 updatedPost.tags.should.have.enumerable(0).with.properties({name: 'tag2', id: postJSON.tags[1].id});529 updatedPost.tags.should.have.enumerable(1).with.properties({name: 'existing-tag-b', id: tagJSON[1].id});530 updatedPost.tags.should.have.enumerable(2).with.properties({name: 'tag3', id: postJSON.tags[2].id});531 updatedPost.tags.should.have.enumerable(3).with.property('name', 'betty');532 updatedPost.tags.should.have.enumerable(4).with.properties({name: 'tag1', id: postJSON.tags[0].id});533 updatedPost.tags.should.have.enumerable(5).with.property('name', 'bob');534 updatedPost.tags.should.have.enumerable(6).with.properties({name: 'existing tag a', id: tagJSON[0].id});535 done();536 }).catch(done);537 });538 });539 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import { post, postjson, postform } from '../../utils/base';2export default {3 //训练营标签列表4 selectCampTypeList(param) {5 let reqdata = param ? param : {};6 return postjson('/campType/selectCampTypeList', reqdata, {})7 },8 //训练营标签列表2 商品用的9 selectCampTypeList2(param) {10 let reqdata = param ? param : {};11 return postjson('/campType/selectCampTypeList2', reqdata, {})12 },13 //训练营标签列表3 课程用的14 selectCampTypeList3(param) {15 let reqdata = param ? param : {};16 return postjson('/campType/selectCampTypeList3', reqdata, {})17 },18 //新建或者修改标签19 campType_insertOrUpdate(param) {20 let reqdata = param ? param : {};21 return postjson('/campType/insertOrUpdate', reqdata, {})22 },23 //新建或者修改标签24 25 campClass_nameChange(param) {26 let reqdata = param ? param : {};27 return postjson('/trainingCampLog/updateTrainingCampName', reqdata, {})28 },29 //删除训练营标签30 campType_deleteById(param) {31 let reqdata = param ? param : {};32 return postjson('/campType/deleteById', reqdata, {})33 },34 // 创建训练营选择模板列表35 trainingCampLog_selectCreateTemplateList(param) {36 let reqdata = param ? param : {};37 return postjson('/trainingCampLog/selectCreateTemplateList', reqdata, {})38 },39 // 训练营上下架40 trainingCampLog_updateCampStatus2(param) {41 let reqdata = param ? param : {};42 return postjson('/trainingCampLog/updateCampStatus2', reqdata, {})43 },44 //训练营图片上传45 trainingCampLog_insertPictures(param) {46 let reqdata = param ? param : {};47 return postform('/trainingCampLog/insertPictures', reqdata, {})48 },49 // 训练营删除图片50 trainingCampLog_deleteImg(param) {51 let reqdata = param ? param : {};52 return post('/trainingCampLog/deleteImg', reqdata, {})53 },54 // 新建或修改训练营55 trainingCampLog_createOrUpdateTrainingCamp(param) {56 let reqdata = param ? param : {};57 return postjson('/trainingCampLog/createOrUpdateTrainingCamp', reqdata, {})58 },59 // 查询训练营详情60 trainingCampLog_selectCampManagement(param) {61 let reqdata = param ? param : {};62 return postjson('/trainingCampLog/selectCampManagement', reqdata, {})63 },64 // 查询训练营的任务列表65 trainingCampLog_selectCampTaskList(param) {66 let reqdata = param ? param : {};67 return postjson('/trainingCampLog/selectCampTaskList', reqdata, {})68 },69 // 创建或修改训练营任务70 trainingCampLog_insertOrUpdateCampTask(param) {71 let reqdata = param ? param : {};72 return postjson('/trainingCampLog/insertOrUpdateCampTask', reqdata, {})73 },74 // 新增或修改任务中视频75 trainingCampLog_insertTasksDetail(param) {76 let reqdata = param ? param : {};77 return postjson('/trainingCampLog/insertTasksDetail', reqdata, {})78 },79 // 获取视频列表 任务选择80 trainingCampLog_selectVideoLibrary(param) {81 let reqdata = param ? param : {};82 return postjson('/trainingCampLog/selectVideoLibrary', reqdata, {})83 },84 // 获取视频列表 资源库85 video_selectVideoLibraryList(param) {86 let reqdata = param ? param : {};87 return postjson('/video/selectVideoLibraryList', reqdata, {})88 },89 // 新增或者修改任务中作业90 trainingCampLog_insertcoursewareList(param) {91 let reqdata = param ? param : {};92 return postjson('/trainingCampLog/insertCampCourseWare', reqdata, {})93 },94 // 作业模板列表95 homeworkDocument_selectHomeworkTemplate(param) {96 let reqdata = param ? param : {};97 return postjson('/homeworkDocument/selectHomeworkTemplate', reqdata, {})98 },99 // 新增或者修改任务中作业100 trainingCampLog_insertTasksHomework(param) {101 let reqdata = param ? param : {};102 return postjson('/trainingCampLog/insertTasksHomework', reqdata, {})103 },104 // 删除任务中作业105 trainingCampLog_deleteCampHomeworkInfo(param) {106 let reqdata = param ? param : {};107 return postjson('/trainingCampLog/deleteCampHomeworkInfo', reqdata, {})108 },109 // 删除训练营中任务110 trainingCampLog_deleteCampTask(param) {111 let reqdata = param ? param : {};112 return postjson('/trainingCampLog/deleteCampTask', reqdata, {})113 },114 // 训练营模板列表115 trainingCampLog_selectCampTemplateList(param) {116 let reqdata = param ? param : {};117 return postjson('/trainingCampLog/selectCampTemplateList', reqdata, {})118 },119 // 训练营排序数据120 trainingCampLog_selectSortList(param) {121 let reqdata = param ? param : {};122 return postjson('/trainingCampLog/selectSortList', reqdata, {})123 },124 //排序所有训练营商品125 trainingCampLog_updateSort (param) {126 let reqdata = param ? param : {};127 return postjson('/trainingCampLog/updateSort', reqdata, {})128 },129 // 训练营管理(发布版本)130 trainingCampLog_selectCampList(param) {131 let reqdata = param ? param : {};132 return postjson('/trainingCampLog/selectCampList', reqdata, {})133 },134 // 训练营计划列表135 forecast_selectCampPlanList(param) {136 let reqdata = param ? param : {};137 return postjson('/forecast/selectCampPlanList', reqdata, {})138 },139 // 教练列表140 forecast_selectCoachList(param) {141 let reqdata = param ? param : {};142 return postjson('/forecast/selectCoachList', reqdata, {})143 },144 // 更新训练营计划145 trainingCampLog_updateCampClassInfo(param) {146 let reqdata = param ? param : {};147 return postjson('/trainingCampLog/updatePlanCamp', reqdata, {})148 },149 // 分享连接150 trainingCampLog_selectShareUrl(param) {151 let reqdata = param ? param : {};152 return postjson('/forecast/selectShareUrl', reqdata, {})153 },154 // 提醒教练155 forecast_campPlanPush(param) {156 let reqdata = param ? param : {};157 return postjson('/forecast/campPlanPush', reqdata, {})158 },159 // 报名学员列表160 forecast_selectForecastList(param) {161 let reqdata = param ? param : {};162 return postjson('/forecast/selectForecastList', reqdata, {})163 },164 // add报名学员列表165 forecast_add(param) {166 let reqdata = param ? param : {};167 return postjson('/forecast/add', reqdata, {})168 },169 // 删除预报名学员170 forecast_delete(param) {171 let reqdata = param ? param : {};172 return postjson('/forecast/delete', reqdata, {})173 },174 // 更新支付状态175 forecast_updatePayType(param) {176 let reqdata = param ? param : {};177 return postjson('/forecast/updatePayType', reqdata, {})178 },179 // 训练营(课程)查询列表(log)180 trainingCampLog_selectCampLogList(param) {181 let reqdata = param ? param : {};182 return postjson('/trainingCampLog/selectCampLogList', reqdata, {})183 },184 // 创建训练营选择模板列表185 trainingCampLog_selectCreateTemplateList(param) {186 let reqdata = param ? param : {};187 return postjson('/trainingCampLog/selectCreateTemplateList', reqdata, {})188 },189 // 复制训练营190 trainingCampLog_insertCopyCampLog(param) {191 let reqdata = param ? param : {};192 return postjson('/trainingCampLog/insertCopyCampLog', reqdata, {})193 },194 // 删除训练营log表数据195 trainingCampLog_deleteCampLog(param) {196 let reqdata = param ? param : {};197 return postjson('/trainingCampLog/deleteCampLog', reqdata, {})198 },199 // 训练营预览接口200 trainingCampLog_selectCampInfo(param) {201 let reqdata = param ? param : {};202 return postjson('/trainingCampLog/selectCampInfo', reqdata, {})203 },204 // 训练营选择教练接口205 trainingCampLog_selectCoachList(param) {206 let reqdata = param ? param : {};207 return postjson('/trainingCampLog/selectCoachList', reqdata, {})208 },209 // 证书训练营列表210 student_selectEndCampList(param) {211 let reqdata = param ? param : {};212 return postjson('/student/selectEndCampList', reqdata, {})213 },214 // 证书学员列表215 student_selectCertificateStudentList(param) {216 let reqdata = param ? param : {};217 return postjson('/student/selectCertificateStudentList', reqdata, {})218 },219 // 查询学员列表220 student_selectCampStudentList(param) {221 let reqdata = param ? param : {};222 return postjson('/student/selectCampStudentList', reqdata, {})223 },224 //删除训练营内的学员225 student_deleteStudent(param) {226 let reqdata = param ? param : {};227 return postjson('/student/deleteStudent', reqdata, {})228 },229 //添加学员230 student_addStudent(param) {231 let reqdata = param ? param : {};232 return postjson('/student/addStudent', reqdata, {})233 },234 //编辑学员235 student_editStudent(param) {236 let reqdata = param ? param : {};237 return postjson('/student/updateCampStudent', reqdata, {})238 },239 //心得--查询240 experience_selectExperienceByCampId(param) {241 let reqdata = param ? param : {};242 return postjson('/experience/selectExperienceByCampId', reqdata, {})243 },244 //心得--创建和修改245 experience_insertExperienceByCampId(param) {246 let reqdata = param ? param : {};247 return postjson('/experience/insertExperienceByCampId', reqdata, {})248 },249 // 提交审核250 trainingCampLog_updateStatus(param) {251 let reqdata = param ? param : {};252 return postjson('/trainingCampLog/commitStatus', reqdata, {})253 },254 // 查询训练营审核发布权限255 eduUser_selectToExamine(param) {256 let reqdata = param ? param : {};257 return postjson('/eduUser/selectToExamine', reqdata, {})258 },259 // 训练营审核接口260 trainingCampLog_updateCampStatus(param) {261 let reqdata = param ? param : {};262 return postjson('/trainingCampLog/updateCampStatus', reqdata, {})263 },264 // 发布测试265 notAuth_testReleseCamp(param) {266 let reqdata = param ? param : {};267 return postjson('/notAuth/testReleseCamp', reqdata, {})268 },269 // 发布270 trainingCampLog_eduReless(param) {271 let reqdata = param ? param : {};272 return postjson('/trainingCampLog/eduReless', reqdata, {})273 },274 // 获取证书列表275 student_selectCertificationList(param) {276 let reqdata = param ? param : {};277 return postjson('/student/selectCertificationList', reqdata, {})278 },279 // 上传证书280 student_addCertificate(param) {281 let reqdata = param ? param : {};282 return postjson('/student/addCertificate', reqdata, {})283 },284 // 训练营查询285 search_camp(param) {286 let reqdata = param ? param : {};287 return postjson('/campComment/selectCamp', reqdata, {})288 },289 // 学员评价列表查询290 student_comment_list(param) {291 let reqdata = param ? param : {};292 return postjson('/campComment/list', reqdata, {})293 },294 // 学员评价类型修改295 student_comment_updateType(param) {296 let reqdata = param ? param : {};297 return postjson('/campComment/updateType', reqdata, {})298 },299 // 学员评价类型新增300 student_comment_insert(param) {301 let reqdata = param ? param : {};302 return postform('/campComment/insert', reqdata, {})303 },304 // 优秀作业列表查询305 student_goodJod_list(param) {306 let reqdata = param ? param : {};307 return postjson('/campHomeworkLog/list', reqdata, {})308 },309 // 优秀作业类型修改310 student_goodJob_updateType(param) {311 let reqdata = param ? param : {};312 return postjson('/campHomeworkLog/updateType', reqdata, {})313 },314 // 训练营下任务315 camp_task_list(param) {316 let reqdata = param ? param : {};317 return postjson('/campHomeworkLog/selectTaskList', reqdata, {})318 },319 // 任务下作业320 task_homework_list(param) {321 let reqdata = param ? param : {};322 return postjson('/campHomeworkLog/selectTaskHomeworkList', reqdata, {})323 },324 // 优秀作业新增325 student_goodJob_insert(param) {326 let reqdata = param ? param : {};327 return postform('/campHomeworkLog/insert', reqdata, {})328 },329 // 精彩分享列表查询330 student_share_list(param) {331 let reqdata = param ? param : {};332 return postjson('/campWonderfulShare/selectShareList', reqdata, {})333 },334 // 播放列表——全部335 student_share_video_list(param) {336 let reqdata = param ? param : {};337 return postjson('/campWonderfulShare/selectShareVideoList', reqdata, {})338 },339 // 新建或者更新精彩分享340 student_share_insert(param) {341 let reqdata = param ? param : {};342 return postjson('/campWonderfulShare/update', reqdata, {})343 },344 // 训练营统计查询查询 进入页面最上面一排345 camp_statistics_check(param) {346 let reqdata = param ? param : {};347 return postjson('/campStatistic/selectCampStatistic', reqdata, {})348 },349 // 训练营学员统计查询 进入页面表格350 camp_student_statistics_list(param) {351 let reqdata = param ? param : {};352 return postjson('/campStatistic/selectStudentStatisticList', reqdata, {})353 },354 // 训练营学员作业统计查询 点击单个学员查询355 camp_student_statistics_info(param) {356 let reqdata = param ? param : {};357 return postjson('/campStatistic/selectStudentHomeworkStatistic', reqdata, {})358 },359 // 导出表360 export_and_user(param) {361 let reqdata = param ? param : {};362 return postjson('/campStatistic/exportAndUser', reqdata, {})363 },364 // 标杆作业列表查询365 student_poleJod_list(param) {366 let reqdata = param ? param : {};367 return postjson('/benchmarking/selectList', reqdata, {})368 },369 // 标杆作业类型修改370 student_poleJob_updateType(param) {371 let reqdata = param ? param : {};372 return postjson('/benchmarking/updateType', reqdata, {})373 },374 // 标杆作业新增375 student_poleJob_insert(param) {376 let reqdata = param ? param : {};377 return postform('/benchmarking/insert', reqdata, {})378 },...

Full Screen

Full Screen

posts.service.ts

Source:posts.service.ts Github

copy

Full Screen

1import { Injectable } from '@angular/core';2import { HttpClient } from '@angular/common/http';3import { Observable, throwError, BehaviorSubject } from 'rxjs';4import { catchError } from 'rxjs/operators';5import { IPost } from '../models/IPost';6import { PostClass } from '../models/PostClass';7import { CUSTOM_FIELD_COUNTRY_ID } from '../Constants';8@Injectable({9 providedIn: 'root'10})11export class PostsService {12 url: string = 'https://api.smartrecruiters.com/v1/companies/smartrecruiters/postings';13 postsArray: IPost[] = [];14 private postsSource = new BehaviorSubject<IPost[]>([]);15 postsReference = this.postsSource.asObservable();16 constructor(private http: HttpClient) { }17 /*---HTTP REQUESTS-------------------------------------*/18 getAllPosts(): Observable<any> {19 /* OPTION1 - FROM JSON LOCAL FILE: */20 return this.getLocalJSON();21 /* // OPTION2 - FROM HTTP SERVICE:22 let data = this.http23 .get(this.url)24 .pipe(catchError(this.handleError));25 return data;26 */27 }28 getPostById(id: string): Observable<any> {29 /* OPTION1 - FROM JSON LOCAL FILE: */30 return this.getLocalJSON(id);31 /* // OPTION2 - FROM HTTP SERVICE:32 let data = this.http33 .get(`${this.url}/${id}`)34 .pipe(catchError(this.handleError));35 return data;36 */37 }38 /*---END OF HTTP REQUESTS-------------------------------------*/39 getPostsInitialization() {40 this.postsArray = []; //Reset array before adding new objects.41 this.getAllPosts().subscribe(data => {42 if (data && data.content) {43 data.content.map(postJSON => {44 if (postJSON) {45 //map to a Post object (model)46 this.postsArray.push(this.jsonToPostMapper(postJSON));47 }48 });49 // broadcast postsLists to other components50 this.postsSource.next(this.postsArray);51 }52 });53 }54 jsonToPostMapper(postJSON: any): IPost {55 let post: PostClass = new PostClass();56 if (postJSON.id) {57 post.id = postJSON.id;58 }59 if (postJSON.name) {60 post.name = postJSON.name;61 }62 if (postJSON.location && postJSON.location.city) {63 post.city = postJSON.location.city;64 }65 if (postJSON.customField66 && postJSON.customField.length > 167 && postJSON.customField[1]68 && postJSON.customField[1].fieldId69 && postJSON.customField[1].fieldId === CUSTOM_FIELD_COUNTRY_ID70 && postJSON.customField[1].valueLabel) {71 post.country = {72 code: postJSON.customField[1].valueId,73 name: postJSON.customField[1].valueLabel74 };75 }76 if (postJSON.department77 && postJSON.department.id78 && postJSON.department.label) {79 post.department = {80 id: postJSON.department.id,81 name: postJSON.department.label82 };83 }84 if (postJSON.company && postJSON.company.name) {85 post.companyName = postJSON.company.name;86 }87 //Sections:88 if (postJSON.jobAd && postJSON.jobAd.sections) {89 if (postJSON.jobAd.sections.companyDescription90 && postJSON.jobAd.sections.companyDescription.text) {91 post.companyDescription = postJSON.jobAd.sections.companyDescription.text;92 }93 if (postJSON.jobAd.sections.jobDescription94 && postJSON.jobAd.sections.jobDescription.text) {95 post.jobDescription = postJSON.jobAd.sections.jobDescription.text;96 }97 if (postJSON.jobAd.sections.qualifications98 && postJSON.jobAd.sections.qualifications.text) {99 post.qualifications = postJSON.jobAd.sections.qualifications.text;100 }101 if (postJSON.jobAd.sections.additionalInformation102 && postJSON.jobAd.sections.additionalInformation.text) {103 post.additionalInfo = postJSON.jobAd.sections.additionalInformation.text;104 }105 }106 return post;107 }108 handleError(error) {109 let errorMessage = '';110 if (error.error instanceof ErrorEvent) {111 // client-side error112 errorMessage = `Error: ${error.error.message}`;113 } else {114 // server-side error115 errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;116 }117 return throwError(errorMessage);118 }119 getLocalJSON(id?: string): Observable<any> {120 return id ? this.http.get(`assets/${id}.json`) : this.http.get("assets/data.json");121 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const http = require("http");2const options = {3 headers: {4 },5};6const req = http.request(options, (res) => {7 console.log(`statusCode: ${res.statusCode}`);8 res.on("data", (d) => {9 process.stdout.write(d);10 });11});12req.on("error", (error) => {13 console.error(error);14});15req.write(16 JSON.stringify({17 {18 {19 equals: {20 },21 },22 {23 is: {24 headers: {25 },26 body: JSON.stringify({27 }),28 },29 },30 },31 })32);33req.end();34{"message":"Hello World!"}

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 json: {4 {5 {6 "is": {7 "headers": {8 },9 "body": {10 }11 }12 }13 }14 }15};16request(options, function (error, response, body) {17 console.log(body);18});19var request = require('request');20var options = {21 json: {22 {23 {24 "is": {25 "headers": {26 },27 "body": {28 }29 }30 }31 },32 {33 {34 "is": {35 "headers": {36 },37 "body": {38 }39 }40 }41 }42 }43};44request(options, function (error, response, body) {45 console.log(body);46});47var request = require('request');48var options = {49};50request(options, function (error, response, body) {51 console.log(body);52});

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 json: {4 {5 {6 "is": {7 "headers": {8 },9 "body": {10 }11 }12 }13 }14 }15};16request(options, function (error, response, body) {17 if (!error && response.statusCode == 201) {18 console.log(body);19 }20});21var request = require('request');22var options = {23 json: {24 {25 {26 "is": {27 "headers": {28 },29 "body": {30 }31 }32 }33 }34 }35};36request(options, function (error, response, body) {37 if (!error && response.statusCode == 201) {38 console.log(body);39 }40});41var request = require('request');42var options = {43 json: {44 {45 {46 "is": {47 "headers": {48 },49 "body": {50 }51 }52 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 json: {4 {5 {6 "is": {7 "headers": {8 },9 "body": {10 }11 }12 }13 }14 }15};16function callback(error, response, body) {17 if (!error && response.statusCode == 201) {18 console.log(body);19 }20}21request(options, callback);22var request = require('request');23var options = {24 json: {25 {26 {27 "is": {28 "headers": {29 },30 "body": {31 }32 }33 }34 }35 }36};37function callback(error, response, body) {38 if (!error && response.statusCode == 201) {39 console.log(body);40 }41}42request(options, callback);43var request = require('request');44var options = {45 json: {46 {47 {48 "is": {49 "headers": {50 },51 "body": {52 }53 }54 }55 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const rp = require('request-promise');2const options = {3 body: {4 stubs: [{5 predicates: [{6 equals: {7 }8 }],9 responses: [{10 is: {11 headers: {12 },13 body: JSON.stringify({14 })15 }16 }]17 }]18 },19};20rp(options)21 .then(function (parsedBody) {22 console.log(parsedBody);23 })24 .catch(function (err) {25 console.log(err);26 });27{ port: 3000, protocol: 'http', numberOfRequests: 0, stubs: [ { predicates: [ [Object] ], responses: [ [Object] ] } ], _links: { self: { href: '/imposters/3000' } } }28{29}30{ port: 3000, protocol: 'http', numberOfRequests: 0, stubs: [ { predicates: [ [Object] ], responses: [ [Object] ] } ], _links: { self: { href: '/imposters/3000' } } }31{ errors: [ 'Cannot DELETE /imposters/3000' ] }

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2 {3 {4 {5 is: {6 headers: {7 },8 body: JSON.stringify({ success: true })9 }10 }11 }12 }13];14mb.postJSON('/imposters', imposters, function (error, response) {15 if (error) {16 console.error('Error creating imposter: ', error);17 }18 else {19 console.log('Created imposter');20 }21});22var mb = require('mountebank');23 {24 {25 {26 is: {27 headers: {28 },29 body: JSON.stringify({ success: true })30 }31 }32 }33 }34];35mb.post('/imposters', imposters, function (error, response) {36 if (error) {37 console.error('Error creating imposter: ', error);38 }39 else {40 console.log('Created imposter');41 }42});43var mb = require('mountebank');44mb.getJSON('/imposters', function (error, response) {45 if (error) {46 console.error('Error getting imposters: ', error);47 }48 else {49 console.log('Got imposters: ', response.body);50 }51});52var mb = require('mountebank');53mb.get('/imposters', function (error, response) {54 if (error) {55 console.error('Error getting imposters: ', error);56 }57 else {58 console.log('Got imposters: ', response.body);59 }60});61var mb = require('mountebank');62mb.deleteJSON('/imposters/3000', function (

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var request = require('request');3var mbHelper = mb.create({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log' });4mbHelper.postJSON('/imposters', {5 {6 {7 is: {8 }9 }10 }11}, function (error, response) {12 if (error) {13 console.error('Failed to create imposter: ' + error.message);14 } else {15 console.log(body);16 mbHelper.del('/imposters/' + response.port, function (error) {17 if (error) {18 console.error('Failed to delete imposter: ' + error.message);19 } else {20 console.log('Deleted imposter');21 }22 });23 });24 }25});26{27 "dependencies": {28 }29}

Full Screen

Using AI Code Generation

copy

Full Screen

1var postJSON = require('mbjs').postJSON;2var options = {3 headers: {4 }5};6 {7 {8 {9 is: {10 headers: {11 },12 body: JSON.stringify({foo: 'bar'})13 }14 }15 }16 }17];18postJSON(options, imposters, function (error, response) {19 if (error) {20 console.error('Error posting JSON:', error);21 } else {22 console.log('Response:', response);23 }24});25var postJSON = require('mbjs').postJSON;26var options = {27 headers: {28 }29};30 {31 {32 {33 is: {34 headers: {35 },36 body: JSON.stringify({foo: 'bar'})37 }38 }39 }40 }41];42postJSON(options, imposters, function (error, response) {43 if (error) {44 console.error('Error posting JSON:', error);45 } else {46 console.log('Response:', response);47 }48});49var postJSON = require('mbjs').postJSON;50var options = {51 headers: {52 }53};54 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var postJSON = function(url, obj) {2 var request = require('request');3 request.post({4 }, function(error, response, body) {5 console.log(body);6 });7};8var getJSON = function(url) {9 var request = require('request');10 request.get({11 }, function(error, response, body) {12 console.log(body);13 });14};15var deleteJSON = function(url) {16 var request = require('request');17 request.del({18 }, function(error, response, body) {19 console.log(body);20 });21};22var putJSON = function(url, obj) {23 var request = require('request');24 request.put({25 }, function(error, response, body) {26 console.log(body);27 });28};29var patchJSON = function(url, obj) {30 var request = require('request');31 request.patch({32 }, function(error, response, body) {33 console.log(body);34 });35};36var headJSON = function(url) {37 var request = require('request');38 request.head({39 }, function(error, response, body) {40 console.log(body);41 });42};43var optionsJSON = function(url) {44 var request = require('request');45 request.options({46 }, function(error, response, body) {47 console.log(body);48 });49};50var deleteJSON = function(url) {51 var request = require('request');52 request.del({53 }, function(error, response, body) {54 console.log(body);55 });56};57var deleteJSON = function(url) {58 var request = require('

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