Best JavaScript code snippet using qawolf
broadcast.service.ts
Source:broadcast.service.ts
1import {Injectable} from '@angular/core';2import {HttpClient, HttpParams} from "@angular/common/http";3import {environment} from "environments/environment";4import {5 BroadcastConfirmation,6 BroadcastContent,7 BroadcastCost,8 BroadcastMembers,9 BroadcastRequest,10 BroadcastSchedule,11 BroadcastTypes12} from "./model/broadcast-request";13import {DateTimeUtils} from "../utils/DateTimeUtils";14import {BroadcastParams, getBroadcastParams} from "./model/broadcast-params";15import {BehaviorSubject, Observable} from "rxjs";16import { map } from 'rxjs/operators';17import {Router} from "@angular/router";18import {Broadcast, BroadcastPage, transform} from './model/broadcast';19import * as moment from 'moment-mini-ts';20import {LocalStorageService} from "../utils/local-storage.service";21@Injectable()22export class BroadcastService {23 fetchUrlBase = environment.backendAppUrl + "/api/broadcast/fetch/";24 createUrlBase = environment.backendAppUrl + "/api/broadcast/create/";25 costThisMonthUrl = environment.backendAppUrl + "/api/broadcast/cost-this-month";26 shortenLinkUrl = environment.backendAppUrl + "/api/broadcast/shorten/link";27 28 downloadMsgsReportUrl = environment.backendAppUrl + "/api/broadcast/sending-report";29 downloadErrorReportUrl = environment.backendAppUrl + "/api/broadcast/error-report";30 resendUrl = environment.backendAppUrl + "/api/broadcast/resend";31 cancelUrl = environment.backendAppUrl + "/api/broadcast/cancel";32 public createRequest: BroadcastRequest = new BroadcastRequest();33 private createCounts: BroadcastCost = new BroadcastCost();34 private _createParams: BroadcastParams = new BroadcastParams();35 public createParams: BehaviorSubject<BroadcastParams> = new BehaviorSubject<BroadcastParams>(null);36 public pages: string[] = ['types', 'content', 'members', 'schedule'];37 public latestStep: number = 1; // in case we go backwards38 public currentStep: number = 1;39 public loadedFromCache: boolean = false;40 constructor(private httpClient: HttpClient, private router: Router, private localStorageService: LocalStorageService) {41 // look for anything cached in here (constructor, not initCreate) so it's available to the route42 this.loadBroadcast();43 }44 fetchCreateParams(type: string, entityUid: string) {45 const fullUrl = this.createUrlBase + type + "/info/" + entityUid;46 this.httpClient.get<BroadcastParams>(fullUrl).subscribe(result => {47 console.log("create fetch result: ", result);48 this._createParams = getBroadcastParams(result);49 console.log("after transform: ", this._createParams);50 this.createParams.next(getBroadcastParams(result));51 return result;52 });53 }54 getCreateParams(): BroadcastParams {55 return this._createParams;56 }57 initCreate(type: string, parentId: string) {58 console.log(`type: ${type}, parentId: ${parentId}`);59 if (this.createRequest.type != type || this.createRequest.parentId != parentId) {60 console.log("create type or parent switched, clearing store");61 if (this.loadedFromCache) {62 // something was sitting in cache, but user switched entity or type, so remove63 this.clearBroadcast();64 }65 this.createRequest.type = type;66 this.createRequest.parentId = parentId;67 this.createRequest.broadcastId = this._createParams.broadcastId;68 this.latestStep = 1;69 }70 }71 getTypes(): BroadcastTypes {72 return {73 shortMessage: this.createRequest.sendShortMessages,74 email: this.createRequest.sendEmail,75 facebook: this.createRequest.postToFacebook,76 facebookPages: this.createRequest.facebookPages,77 twitter: this.createRequest.postToTwitter,78 twitterAccount: this.createRequest.twitterAccount79 };80 }81 setTypes(types: BroadcastTypes) {82 this.createRequest.sendShortMessages = types.shortMessage;83 this.createRequest.sendEmail = types.email;84 this.createRequest.postToFacebook = types.facebook;85 this.createRequest.facebookPages = types.facebookPages;86 this.createRequest.postToTwitter = types.twitter;87 this.createRequest.twitterAccount = types.twitterAccount;88 this.saveBroadcast();89 }90 getContent(): BroadcastContent {91 return {92 title: this.createRequest.title,93 shortMessage: this.createRequest.shortMessageString,94 emailContent: this.createRequest.emailContent,95 emailAttachmentKeys: this.createRequest.emailAttachmentKeys,96 facebookPost: this.createRequest.facebookContent,97 facebookLink: this.createRequest.facebookLink,98 facebookLinkCaption: this.createRequest.facebookLinkCaption,99 facebookImageKey: this.createRequest.facebookImageKey,100 twitterPost: this.createRequest.twitterContent,101 twitterLink: this.createRequest.twitterLink,102 twitterLinkCaption: this.createRequest.twitterLinkCaption,103 twitterImageKey: this.createRequest.twitterImageKey,104 smsMergeField: "",105 emailMergeField: ""106 }107 }108 setContent(content: BroadcastContent) {109 this.createRequest.title = content.title;110 this.createRequest.shortMessageString = content.shortMessage;111 this.createRequest.emailContent = content.emailContent;112 this.createRequest.emailAttachmentKeys = content.emailAttachmentKeys;113 this.createRequest.facebookContent = content.facebookPost;114 this.createRequest.facebookLink = content.facebookLink;115 this.createRequest.facebookImageKey = content.facebookImageKey;116 this.createRequest.twitterContent = content.twitterPost;117 this.createRequest.twitterLink = content.twitterLink;118 this.createRequest.twitterImageKey = content.twitterImageKey;119 this.saveBroadcast();120 // console.log("saved fb image key: ", this.createRequest.facebookImageKey);121 }122 getMembers(): BroadcastMembers {123 return {124 selectionType: this.createRequest.selectionType,125 taskTeams: this.createRequest.taskTeams,126 memberFilter: this.createRequest.getMemberFilter(),127 skipSmsIfEmail: this.createRequest.skipSmsIfEmail128 }129 }130 setMembers(members: BroadcastMembers) {131 this.createRequest.selectionType = members.selectionType;132 this.createRequest.taskTeams = members.taskTeams;133 this.createRequest.setMemberFilter(members.selectionType, members.memberFilter);134 this.createRequest.skipSmsIfEmail = members.skipSmsIfEmail;135 this.saveBroadcast();136 }137 setMessageCounts(costs: BroadcastCost) {138 this.createCounts = costs;139 }140 getSchedule(): BroadcastSchedule {141 return {142 sendType: this.createRequest.sendType,143 sendMoment: moment(this.createRequest.sendDateTimeMillis),144 sendDateTimeMillis: this.createRequest.sendDateTimeMillis,145 sendDateString: moment(this.createRequest.sendDateTimeMillis).format("HH:mm, ddd MM YYYY"),146 dateEpochMillis: DateTimeUtils.dateFromDate(new Date()),147 timeEpochMillis: DateTimeUtils.timeFromDate(new Date())148 }149 }150 setSchedule(schedule: BroadcastSchedule) {151 console.log("broadcast now looks like: ", this.createRequest);152 this.createRequest.sendType = schedule.sendType;153 this.createRequest.sendDateString = schedule.sendDateString;154 this.createRequest.sendDateTimeMillis = schedule.sendDateTimeMillis;155 this.saveBroadcast(); // since we remain on this step156 }157 getConfirmationFields(): BroadcastConfirmation {158 console.log("getting confirmation fields, request: ", this.createRequest);159 let cn = new BroadcastConfirmation();160 cn.sendShortMessage = this.createRequest.sendShortMessages;161 cn.sendEmail = this.createRequest.sendEmail;162 cn.postFacebook = this.createRequest.postToFacebook;163 cn.fbPageNames = this.getFbDisplayNames(this.createRequest.facebookPages);164 cn.postTwitter = this.createRequest.postToTwitter;165 cn.twitterAccount = this.createRequest.twitterAccount;166 console.log("stored count: ", this.createCounts.totalNumber);167 cn.totalMemberCount = this.createCounts.totalNumber;168 console.log("total member count: ", cn.totalMemberCount);169 cn.smsNumber = this.createCounts.smsNumber;170 cn.sendEmailCount = this.createCounts.emailNumber;171 cn.broadcastCost = this.createCounts.broadcastCost;172 cn.provinces = this.createRequest.provinces;173 cn.topics = this.createRequest.topics;174 cn.sendTimeDescription = this.createRequest.sendType;175 cn.sendDateString = this.createRequest.sendDateString;176 return cn;177 }178 private getFbDisplayNames(fbUserIds: string[]): string[] {179 if (this._createParams.facebookPages && fbUserIds) {180 return fbUserIds.map(fbUserId => this._createParams.facebookPages.find(page => page.pageId == fbUserId).pageName);181 } else {182 return [];183 }184 }185 sendBroadcast() {186 const fullUrl = this.createUrlBase + this.createRequest.type + "/" + this.createRequest.parentId;187 console.log("sending broadcast, create request = ", this.createRequest);188 return this.httpClient.post(fullUrl, this.createRequest);189 }190 cancelCurrentCreate() {191 let parentRoute = this.createRequest.type == 'campaign' ? '/campaign/' + this.createRequest.parentId :192 '/group/' + this.createRequest.parentId;193 this.clearBroadcast();194 this.router.navigate([parentRoute]);195 return false; // in case called on an anchor tag196 }197 currentType(): string {198 return this.createRequest.type;199 }200 parentId(): string {201 return this.createRequest.parentId;202 }203 parentViewRoute(): string {204 return (this.createRequest) ? (this.createRequest.type == 'campaign' ? '/campaign/' : '/group/') + this.createRequest.parentId :205 '/home';206 }207 inboundGroupUrl(groupId: string): string {208 return environment.frontendAppUrl + "/join/group/" + groupId + "?broadcastId=" + this.createRequest.broadcastId;209 }210 /*211 Below helps persist and retrieve in-progress broadcast212 */213 saveBroadcast() {214 this.localStorageService.setItem('broadcastCreateRequest', JSON.stringify(this.createRequest));215 }216 loadBroadcast() {217 this.createRequest = new BroadcastRequest();218 let storedString = this.localStorageService.getItem('broadcastCreateRequest');219 console.log("Broadcast service loaded, checking if old one in cache: ", storedString);220 if (storedString) {221 let cachedRequest = JSON.parse(storedString);222 this.createRequest.copyFields(cachedRequest);223 } else {224 // console.log("nothing in cache, just return new empty");225 this.createRequest = new BroadcastRequest();226 }227 let storedStep = this.localStorageService.getItem('broadcastCreateStep');228 this.latestStep = Number(storedStep) || 1;229 this.currentStep = this.latestStep;230 }231 clearBroadcast() {232 console.log("cancelling, exiting");233 this.createRequest.clear();234 this.currentStep = 1;235 this.latestStep = 1;236 this.localStorageService.removeItem('broadcastCreateRequest');237 this.localStorageService.removeItem('broadcastCreateStep');238 }239 setPageCompleted(page: string) {240 let nextPage = this.pages.indexOf(page) + 1 + 1;241 // 1 for zero base, 1 to go to next242 if (this.latestStep < nextPage) {243 this.latestStep = nextPage;244 this.localStorageService.setItem('broadcastCreateStep', this.latestStep.toString());245 }246 }247 getGroupBroadcasts(groupUid: string, broadcastSchedule: string, pageNo: number, pageSize: number): Observable<BroadcastPage>{248 let params = new HttpParams()249 .set('page', pageNo.toString())250 .set('size', pageSize.toString())251 .set('sort', 'creationTime,desc')252 .set('broadcastSchedule', broadcastSchedule);253 const fullUrl = this.fetchUrlBase + 'group/' + groupUid;254 return this.httpClient.get<BroadcastPage>(fullUrl, {params: params})255 .pipe(map(256 result => {257 console.log("Group broadcasts json object from server: ", result);258 let transformetContent = result.content.map(transform);259 return new BroadcastPage(260 result.number,261 result.totalPages,262 result.totalElements,263 result.size,264 result.first,265 result.last,266 transformetContent267 )268 }269 ))270 }271 // highly unlikely a campaign will have enough broadcasts to merit pagination272 getCampaignBroadcasts(campaignUid: string): Observable<Broadcast[]> {273 const fullUrl = this.fetchUrlBase + 'campaign/' + campaignUid;274 return this.httpClient.get<Broadcast[]>(fullUrl).pipe(map(list => list.map(transform)));275 }276 sendMeetingBroadcast(meetingUid: string, message: string, sendToOnlyYes: boolean) {277 const fullUrl = this.createUrlBase + "task/MEETING/" + meetingUid;278 let params = new HttpParams().set("message", message).set("sendToAll", "" + !sendToOnlyYes);279 return this.httpClient.post(fullUrl, null, {params: params});280 }281 getCostThisMonth(): Observable<number> {282 return this.httpClient.get<number>(this.costThisMonthUrl)283 .pipe(map(resp => {284 return resp;285 }))286 }287 shortenLink(link: string): Observable<string> {288 let params = new HttpParams().set("link", link);289 return this.httpClient.get(this.shortenLinkUrl, {params: params, responseType: 'text'});290 }291 downloadBroadcastMsgsReport(broadcastUid: string) {292 const fullUrl = this.downloadMsgsReportUrl + "/" + broadcastUid + "/download";293 return this.httpClient.get(fullUrl, { responseType: 'blob' });294 }295 downloadBroadcastErrorReport(broadcastUid: string) {296 const fullUrl = this.downloadErrorReportUrl + "/" + broadcastUid + '/download';297 return this.httpClient.get(fullUrl, { responseType: 'blob' });298 }299 resendBroadcast(broadcastId: string, resendParams) {300 const fullUrl = this.resendUrl + '/' + broadcastId;301 let params = new HttpParams().set('resendText', resendParams['resendText']).set('resendEmail', resendParams['resendEmail'])302 .set('resendFb', resendParams['resendFb']).set('resendTwitter', resendParams['resendTwitter']);303 return this.httpClient.post(fullUrl, null, {params: params});304 }305 cancelBroadcast(broadcastId: string) {306 const fullUrl = this.cancelUrl + '/' + broadcastId;307 return this.httpClient.post(fullUrl, null);308 }...
upload.js
Source:upload.js
1'use strict';2var expect = require('chai').expect;3var index = require('../dist/index.js');4var bsv = require('bsv');5// Do not use this to send money!6// You will lose your bitcoin!7// This is here for testing purposes only8const privateKey = 'L31717p4nUc2e95Vo3urCVML8N4hKuWbivmbpd3EwusqmtvVVL2E';9function sleep(n) { return new Promise(resolve=>setTimeout(resolve,n)); }10describe('uploads', () => {11 it('should return false no key', async () => {12 var createRequest = {13 file: {14 },15 pay: {16 key: ""17 }18 };19 var result = await index.createFile(createRequest);20 expect(result).to.eql({21 success: false,22 message: "key required"23 });24 createRequest = {25 file: {26 },27 pay: {28 key: undefined29 }30 };31 var result = await index.createFile(createRequest);32 expect(result).to.eql({33 success: false,34 message: "key required"35 });36 });37 it('should return false missing file', async () => {38 var createRequest = {39 pay: {40 key: "key1"41 }42 };43 var result = await index.createFile(createRequest);44 expect(result).to.eql({45 success: false,46 message: "file required"47 });48 });49 it('should return false missing file callback', async () => {50 var createRequest = {51 pay: {52 key: "key1"53 }54 };55 await index.createFile(createRequest, (result) => {56 expect(result).to.eql({57 success: false,58 message: "file required"59 });60 });61 });62 it('should return false missing file content', async () => {63 var createRequest = {64 file: {65 },66 pay: {67 key: "key1"68 }69 };70 var result = await index.createFile(createRequest);71 expect(result).to.eql({72 success: false,73 message: "content required"74 });75 });76 it('should return false missing file contentType', async () => {77 var createRequest = {78 file: {79 content: 'hello',80 },81 pay: {82 key: "key1"83 }84 };85 var result = await index.createFile(createRequest);86 expect(result).to.eql({87 success: false,88 message: "contentType required"89 });90 });91 // Uncomment this line to send a real transaction92 it('uploadnow should return success created file utf-8 default', async () => {93 await sleep(6000);94 var createRequest = {95 file: {96 content: 'hello',97 contentType: 'text/plain',98 },99 pay: {100 key: privateKey101 },102 signatures: [103 {104 key: privateKey105 }106 ]107 };108 const address = new bsv.PrivateKey(privateKey).toPublicKey().toAddress().toString();109 const result = await index.createFile(createRequest, function(status) {110 expect(!!status.fee).to.equal(true);111 expect(!!status.rawtx).to.equal(true);112 });113 // Check that the signature can be verified114 /* const expectedSigned1 = [115 '0x31394878696756345179427633744870515663554551797131707a5a56646f417574',116 '0x68656c6c6f',117 '0x746578742f706c61696e',118 '0x7574662d38',119 '0x00',120 '0x7c',121 '0x313550636948473232534e4c514a584d6f5355615756693757537163376843667661',122 '0x424954434f494e5f4543445341',123 '0x31455868536247466945415a4345356565427655785436634256486872705057587a',124 '0x1c654ddcf92e71de7a2221d831ef7bd705e94ee0f8f4b4a62916047e13e1448a836f18f25136001a67be9474ea1e56ed7fda9e309660d4b84660999f047cd8f38f',125 '0x9467df677dc153a88243465d09ca5fe8f7ba8cf9'126 ];127 // Let's verify the signature explictly128 // (It was already verified underneath in building it, but we check again for demo purposes)129 var detectAddressesResult = await index.detectAndVerifyAuthorIdentities(expectedSigned1);130 expect(detectAddressesResult).to.eql({131 const expectedSigned1 = [132 '0x31394878696756345179427633744870515663554551797131707a5a56646f417574',133 '0x68656c6c6f',134 '0x746578742f706c61696e',135 '0x7574662d38',136 '0x00',137 '0x7c',138 '0x313550636948473232534e4c514a584d6f5355615756693757537163376843667661',139 '0x424954434f494e5f4543445341',140 '0x31455868536247466945415a4345356565427655785436634256486872705057587a',141 '0x1c654ddcf92e71de7a2221d831ef7bd705e94ee0f8f4b4a62916047e13e1448a836f18f25136001a67be9474ea1e56ed7fda9e309660d4b84660999f047cd8f38f',142 '0x9467df677dc153a88243465d09ca5fe8f7ba8cf9'143 ];144 });*/145 //const s = new bsv.Script.fromHex('006a2231394878696756345179427633744870515663554551797131707a5a56646f4175740568656c6c6f0a746578742f706c61696e057574662d380100017c22313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f45434453412231336a62683650733670344745664e56625a7070364177715746726b57516d61574e411f7338b68ba98edd91d6151bb6baa17885d4827a35ccfa5e76da7e1df8d8124de37b2c48d129f5c08fd682dfe6ed491dcc4feba5c90af4770fc9bab3afd5d2caed');146 // Now verify by the tx that was created earlier147 var detectAddressesResult = await index.detectAndVerifyAuthorIdentitiesByTx(result.rawtx); // '0100000001f192415cc32c7245f1e6e395760be00a7283c5f203acb4fce7824803740e301f010000008a47304402205e3c84c089e90c7efa4d1d7aeccca2989ef82237e7b8b161112cd72e93d6b1200220129a4f1c4450fdcdba61ca1a765845b8c426e80e6660c1ccaae594bf56661dc04141043cf0a503fd150ad112de4503f7dd17dcdba99e41cd7f8b52315fa1a4f9e499b9493fddcc15a594022f9734b8cf12a068d51328664192f351c3b618e52ae1f85fffffffff020000000000000000d6006a2231394878696756345179427633744870515663554551797131707a5a56646f4175740568656c6c6f0a746578742f706c61696e057574662d380100017c22313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f45434453412231455868536247466945415a4345356565427655785436634256486872705057587a411c654ddcf92e71de7a2221d831ef7bd705e94ee0f8f4b4a62916047e13e1448a836f18f25136001a67be9474ea1e56ed7fda9e309660d4b84660999f047cd8f38f87560700000000001976a9149467df677dc153a88243465d09ca5fe8f7ba8cf988ac00000000');148 console.log(detectAddressesResult);149 expect(detectAddressesResult).to.eql({150 "0": {151 "addresses": [152 {153 "address": "13jbh6Ps6p4GEfNVbZpp6AwqWFrkWQmaWN",154 "fieldIndexesForSignature": [155 0,156 1,157 2,158 3,159 4,160 5,161 6,162 ],163 "pos": 7,164 "verified": true,165 }166 ],167 "signedFullyByAddresses": [168 "13jbh6Ps6p4GEfNVbZpp6AwqWFrkWQmaWN"169 ],170 "verified": true171 }172 });173 });174 // Uncomment this line to send a real transaction175 it('should return success created file utf-8 and signs it with a public key', async () => {176 await sleep(6000);177 var createRequest = {178 file: {179 content: 'Hello world!',180 contentType: 'text/plain',181 },182 pay: {183 key: privateKey184 },185 signatures: [186 {187 key: privateKey188 }189 ]190 };191 var result = await index.createFile(createRequest);192 expect(result.success).to.equal(true);193 });194 // Uncomment this line to send a real transaction195 it('should return success created file utf-8 default', async () => {196 await sleep(6000);197 var createRequest = {198 file: {199 content: JSON.stringify({ foo: "bar" }),200 contentType: 'application/json',201 encoding: 'utf8',202 name: 'file.json',203 tags: ['tag99', 'https://www.bitcoinfiles.org#super-%24-$422-9/#', 'some other tag', '4thtag', '5th element']204 },205 pay: {206 key: privateKey207 }208 };209 var result = await index.createFile(createRequest);210 expect(result.success).to.equal(true);211 });...
create.js
Source:create.js
1'use strict';2var expect = require('chai').expect;3var index = require('../dist/index.js');4var bsv = require('bsv');5// Do not use this to send money!6// You will lose your bitcoin!7// This is here for testing purposes only8const privateKey = '5KLpZB2Sfn4S7QXh6rRynXrVZXXT8zTdQBaj7Ngs3ZHpip5zd8r';9describe('create function test', () => {10 it('should return false no key', async () => {11 var createRequest = {12 file: {13 },14 pay: {15 key: ""16 }17 };18 var result = await index.createFile(createRequest);19 expect(result).to.eql({20 success: false,21 message: "key required"22 });23 createRequest = {24 file: {25 },26 pay: {27 key: undefined28 }29 };30 var result = await index.createFile(createRequest);31 expect(result).to.eql({32 success: false,33 message: "key required"34 });35 });36 it('should return false missing file', async () => {37 var createRequest = {38 pay: {39 key: "key1"40 }41 };42 var result = await index.createFile(createRequest);43 expect(result).to.eql({44 success: false,45 message: "file required"46 });47 });48 it('should return false missing file callback', async () => {49 var createRequest = {50 pay: {51 key: "key1"52 }53 };54 await index.createFile(createRequest, (result) => {55 expect(result).to.eql({56 success: false,57 message: "file required"58 });59 });60 });61 it('should return false missing file content', async () => {62 var createRequest = {63 file: {64 },65 pay: {66 key: "key1"67 }68 };69 var result = await index.createFile(createRequest);70 expect(result).to.eql({71 success: false,72 message: "content required"73 });74 });75 it('should return false missing file contentType', async () => {76 var createRequest = {77 file: {78 content: 'hello',79 },80 pay: {81 key: "key1"82 }83 };84 var result = await index.createFile(createRequest);85 expect(result).to.eql({86 success: false,87 message: "contentType required"88 });89 });90 // Uncomment this line to send a real transaction91 /*it('should return success created file utf-8 default', async () => {92 var createRequest = {93 file: {94 content: 'hello',95 contentType: 'text/plain',96 },97 pay: {98 key: privateKey99 },100 signatures: [101 {102 key: privateKey103 }104 ]105 };106 const address = new bsv.PrivateKey(privateKey).toPublicKey().toAddress().toString();107 var result = await index.createFile(createRequest);108 expect(result.success).to.equal(true);109 // Check that the signature can be verified110 const expectedSigned1 = [111 '0x31394878696756345179427633744870515663554551797131707a5a56646f417574',112 '0x68656c6c6f',113 '0x746578742f706c61696e',114 '0x7574662d38',115 '0x00',116 '0x7c',117 '0x313550636948473232534e4c514a584d6f5355615756693757537163376843667661',118 '0x424954434f494e5f4543445341',119 '0x31455868536247466945415a4345356565427655785436634256486872705057587a',120 '0x1c654ddcf92e71de7a2221d831ef7bd705e94ee0f8f4b4a62916047e13e1448a836f18f25136001a67be9474ea1e56ed7fda9e309660d4b84660999f047cd8f38f',121 '0x9467df677dc153a88243465d09ca5fe8f7ba8cf9'122 ];123 // Let's verify the signature explictly124 // (It was already verified underneath in building it, but we check again for demo purposes)125 var detectAddressesResult = await index.detectAndVerifyAuthorIdentities(expectedSigned1);126 expect(detectAddressesResult).to.eql({127 });128 // Now verify by the tx that was created earlier129 detectAddressesResult = await index.detectAndVerifyAuthorIdentitiesByTx('0100000001f192415cc32c7245f1e6e395760be00a7283c5f203acb4fce7824803740e301f010000008a47304402205e3c84c089e90c7efa4d1d7aeccca2989ef82237e7b8b161112cd72e93d6b1200220129a4f1c4450fdcdba61ca1a765845b8c426e80e6660c1ccaae594bf56661dc04141043cf0a503fd150ad112de4503f7dd17dcdba99e41cd7f8b52315fa1a4f9e499b9493fddcc15a594022f9734b8cf12a068d51328664192f351c3b618e52ae1f85fffffffff020000000000000000d6006a2231394878696756345179427633744870515663554551797131707a5a56646f4175740568656c6c6f0a746578742f706c61696e057574662d380100017c22313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f45434453412231455868536247466945415a4345356565427655785436634256486872705057587a411c654ddcf92e71de7a2221d831ef7bd705e94ee0f8f4b4a62916047e13e1448a836f18f25136001a67be9474ea1e56ed7fda9e309660d4b84660999f047cd8f38f87560700000000001976a9149467df677dc153a88243465d09ca5fe8f7ba8cf988ac00000000');130 console.log(detectAddressesResult);131 expect(detectAddressesResult).to.eql({132 verified: true,133 signedFullyByAddresses: [134 address,135 ],136 addresses: [137 {138 address: address,139 verified: true,140 fieldIndexesForSignature: [141 0,142 1,143 2,144 3,145 4,146 5,147 6148 ],149 pos: 7150 },151 ]152 });153 });*/154 // Uncomment this line to send a real transaction155 /*156 it('should return success created file utf-8 and signs it with a public key', async () => {157 var createRequest = {158 file: {159 content: 'Hello world!',160 contentType: 'text/plain',161 },162 pay: {163 key: privateKey164 },165 signatures: [166 {167 key: privateKey168 }169 ]170 };171 var result = await index.createFile(createRequest);172 console.log('result', result);173 expect(result.success).to.equal(true);174 });175 */176 // Uncomment this line to send a real transaction177 /*178 it('should return success created file utf-8 default', async () => {179 var createRequest = {180 file: {181 content: JSON.stringify({ foo: "bar" }),182 contentType: 'application/json',183 encoding: 'utf8',184 name: 'file.json',185 tags: ['tag99', 'https://www.bitcoinfiles.org#super-%24-$422-9/#', 'some other tag', '4thtag', '5th element']186 },187 pay: {188 key: privateKey189 }190 };191 var result = await index.createFile(createRequest);192 console.log('result', result);193 expect(result.success).to.equal(true);194 });195 */...
index.js
Source:index.js
...35}36/** ****** Account ********/37// Signup API request38export function signin (data) {39 return createRequest('/signin', 'post', defaultHeaders, data)40}41// Login API request42export function signup (data) {43 return createRequest('/signup', 'post', defaultHeaders, data)44}45// Signup API request46export function verify (data) {47 return createRequest('/verify', 'post', defaultHeaders, data)48}49// Restore account API request50export function resetPassword (data) {51 return createRequest('/restore', 'get', defaultHeaders, data)52}53// Login with new password account API request54export function loginNewPassword (data) {55 return createRequest('/restore/password', 'post', defaultHeaders, data)56}57// Change profile data API request58export function changeProfileData (data, headers) {59 return createRequest('/account/profile/update', 'post', customHeaders(headers), data)60}61// GET profile password API request62export function getProfilePassword (data, headers) {63 return createRequest('/account/profile/password', 'get', customHeaders(headers), data)64}65// Change profile password API request66export function changeProfilePassword (data, headers) {67 return createRequest('/account/profile/password/update', 'post', customHeaders(headers), data)68}69// GET actual data user API request70export function renewToken (data, headers) {71 return createRequest('/account/renew-token', 'post', customHeaders(headers), data)72}73// POST user deposit API request74export function makeDeposit (data, headers) {75 return createRequest('/account/deposit', 'post', customHeaders(headers), data)76}77// POST user cashout API request78export function cashout (data, headers) {79 return createRequest('/account/cashout', 'post', customHeaders(headers), data)80}81// GET bets user history API request82export function getUserBetsHistory (data, headers) {83 return createRequest('/account/history/bets', 'get', customHeaders(headers), data)84}85// INTERKASSA: cashout request86export function InterKassaCashout (data, headers) {87 console.log('api/index 108')88 console.log(data)89 console.log(customHeaders(headers))90 return createRequest('/interkassa/cashout', 'post', customHeaders(headers), data)91}92/** ****** BETS ********/93// GetBets API request94export function getBets (data) {95 return createRequest('/bets', 'get', defaultHeaders, data)96}97// getBetsByOne API request98export function getBetsByOne ({ b_id }) {99 return createRequest(`/bets/${b_id}`, 'get', defaultHeaders, null)100}101// CreateBet API request102export function createBet (data, headers) {103 return createRequest('/bets/create', 'post', customHeaders(headers), data)104}105// JoinBet API request106export function joinBet (data, headers) {107 return createRequest('/bets/join', 'post', customHeaders(headers), data)108}109// ADMIN FUNCTIONS110/******************/111// Update bet status API request112export function getBetsNotSelectedWinner (data, headers) {113 return createRequest('/bets/status/not-selected-winner', 'get', customHeaders(headers))114}115// Update bet status API request116export function getBetsNotConfirmed (data, headers) {117 return createRequest('/bets/status/not-confirmed', 'get', customHeaders(headers))118}119// Update bet status API request120export function adminConfirmBet (data, headers) {121 return createRequest('/bets/admin/confirm', 'post', customHeaders(headers), data)122}123// Close bet API request124export function adminCloseBet (data, headers) {125 return createRequest('/bets/admin/close', 'post', customHeaders(headers), data)126}127// Change bet API request128export function adminChangeBet (data, headers) {129 return createRequest('/bets/admin/change', 'post', customHeaders(headers), data)...
Using AI Code Generation
1const { createRequest } = require('qawolf');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const request = await createRequest(page, {8 });9 const response = await request.send();10 console.log(response.body);11 await browser.close();12})();13const { createRequest } = require('qawolf');14const { chromium } = require('playwright');15(async () => {16 const browser = await chromium.launch();17 const context = await browser.newContext();18 const page = await context.newPage();19 const request = await createRequest(page, {20 body: { hello: 'world' },21 });22 const response = await request.send();23 console.log(response.body);24 await browser.close();25})();26const { createRequest } = require('qawolf');27const { chromium } = require('playwright');28(async () => {29 const browser = await chromium.launch();30 const context = await browser.newContext();31 const page = await context.newPage();32 const request = await createRequest(page, {33 headers: {34 },35 });36 const response = await request.send();37 console.log(response.body);38 await browser.close();39})();40const { createRequest } = require('qawolf');41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();46 const request = await createRequest(page, {
Using AI Code Generation
1const { createRequest } = require("@qawolf/web");2const { chromium } = require("playwright");3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click("text=More information");8 await page.click("text=More information");9 await page.click("text=More information");10 const request = await createRequest(page);11 console.log(request);12 await browser.close();13})();14const { createRequest } = require("@qawolf/web");15const { chromium } = require("playwright");16describe("test", () => {17 it("test", async () => {18 const browser = await chromium.launch();19 const context = await browser.newContext();20 const page = await context.newPage();21 await page.click("text=More information");22 await page.click("text=More information");23 await page.click("text=More information");24 const request = await createRequest(page);25 console.log(request);26 await browser.close();27 });28});
Using AI Code Generation
1const { createRequest } = require('qawolf');2const { chromium } = require('playwright-chromium');3const { firefox } = require('playwright-firefox');4const { webkit } = require('playwright-webkit');5const browser = await chromium.launch();6const context = await browser.newContext();7const page = await context.newPage();8const request = await createRequest(page, {9 headers: {10 },11});12const response = await request.send();13console.log(response.status());14await browser.close();15const { chromium } = require('playwright-chromium');16const { firefox } = require('playwright-firefox');17const { webkit } = require('playwright-webkit');18const browser = await chromium.launch();19const context = await browser.newContext();20const page = await context.newPage();21 headers: {22 },23});24const response = await request.send();25console.log(response.status());26await browser.close();27const { chromium } = require('playwright-chromium');28const browser = await chromium.launch();29const context = await browser.newContext();30const page = await context.newPage();31 headers: {32 },33});34const response = await request.send();35console.log(response.status());36await browser.close();37const { firefox } = require('playwright-firefox');38const browser = await firefox.launch();39const context = await browser.newContext();40const page = await context.newPage();41 headers: {42 },43});
Using AI Code Generation
1const qawolf = require("qawolf");2const browser = await qawolf.launch();3const context = await browser.newContext();4const page = await context.newPage();5const request = await qawolf.createRequest(page);6const response = await qawolf.createResponse(page);7await qawolf.register(request, response);8await qawolf.stopVideos();9await context.close();10await browser.close();11const qawolf = require("qawolf");12const browser = await qawolf.launch();13const context = await browser.newContext();14const page = await context.newPage();15const request = await qawolf.createRequest(page);16const response = await qawolf.createResponse(page);17await qawolf.register(request, response);18await qawolf.stopVideos();19await context.close();20await browser.close();21const qawolf = require("qawolf");22const browser = await qawolf.launch();23const context = await browser.newContext();24const page = await context.newPage();25const request = await qawolf.createRequest(page);26const response = await qawolf.createResponse(page);27await qawolf.register(request, response);28await qawolf.stopVideos();29await context.close();30await browser.close();31const qawolf = require("qawolf");32const browser = await qawolf.launch();33const context = await browser.newContext();34const page = await context.newPage();35const request = await qawolf.createRequest(page);36const response = await qawolf.createResponse(page);37await qawolf.register(request, response);38await qawolf.stopVideos();39await context.close();40await browser.close();41const qawolf = require("qawolf");
Using AI Code Generation
1const { createRequest } = require("@qawolf/browser-request");2const { createResponse } = require("@qawolf/browser-response");3const { createServer } = require("http");4const { createWriteStream } = require("fs");5const { join } = require("path");6const { launch } = require("qawolf");7const { createReadStream } = require("fs");8const { createInterface } = require("readline");9const { createWriteStream } = require("fs");10const { join } = require("path");11const { launch } = require("qawolf");12const { createReadStream } = require("fs");13const { createInterface } = require("readline");14const { createWriteStream } = require("fs");15const { join } = require("path");16const { launch } = require("qawolf");17const { createReadStream } = require("fs");18const { createInterface } = require("readline");19const { createWriteStream } = require("fs");20const { join } = require("path");21const { launch } = require("qawolf");22const { createReadStream } = require("fs");23const { createInterface } = require("readline");24const { createWriteStream } = require("fs");25const { join } = require("path");26const { launch } = require("qawolf");27const { createReadStream } = require("fs");28const { createInterface } = require("readline");29const { createWriteStream } = require("fs");30const { join } = require("path");31const { launch } = require("qawolf");32const { createReadStream } = require("fs");33const { createInterface } = require("readline");34const { createWriteStream } = require("fs");35const { join } = require("path");36const { launch } = require("qawolf");37const { createReadStream } = require("fs");38const { createInterface } = require("readline");39const { createWriteStream } = require("fs");40const { join } = require("path");41const { launch } = require("qawolf");42const { createReadStream } = require("fs");43const { createInterface } = require("readline");44const { createWriteStream } = require("fs");45const { join } = require("path");46const { launch } = require("qawolf");47const { createReadStream } = require("fs");48const { createInterface
Using AI Code Generation
1const { createRequest } = require("qawolf");2await context.type("#lst-ib", "Hello World");3await context.click('input[value="Google Search"]');4const { createBrowser } = require("qawolf");5const browser = await createBrowser();6const page = await browser.newPage();7await page.type("#lst-ib", "Hello World");8await page.click('input[value="Google Search"]');9const { createPage } = require("qawolf");10const page = await createPage();11await page.type("#lst-ib", "Hello World");12await page.click('input[value="Google Search"]');13const { createBrowser } = require("qawolf");14const browser = await createBrowser();15const page = await browser.newPage();16await page.type("#lst-ib", "Hello World");17await page.click('input[value="Google Search"]');18const { createRequest } = require("qawolf");19await context.type("#lst-ib", "Hello World");20await context.click('input[value="Google Search"]');21const { createBrowser } = require("qawolf");22const browser = await createBrowser();23const page = await browser.newPage();24await page.type("#lst-ib", "Hello World");25await page.click('input[value="Google Search"]');26const { createPage } = require("qawolf");27const page = await createPage();28await page.type("#lst-ib", "Hello World");29await page.click('input[value="Google Search"]');
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!!