How to use createRequestOptions method in wpt

Best JavaScript code snippet using wpt

api.js

Source:api.js Github

copy

Full Screen

...16}17function auth(idToken) {18 return new Headers({ 'Authorization': 'Bearer '+idToken, 'Connection': 'mobile' });19}20function createRequestOptions(request_type, data, bearer_token = 0) {21 return {22 method: request_type,23 headers: {24 'Authorization': 'Bearer ' + bearer_token,25 'Accept': 'application/json',26 'Content-Type': 'application/json',27 'Connection': 'mobile'28 },29 body: JSON.stringify(data)30 };31}32const Api = {33 fetchSites(user) {34 return request(createEndpoint('/sites'), {headers: auth(user)});35 },36 fetchPrograms(user, site_id) {37 return request(createEndpoint(`/sites/${site_id}/programs`), { headers: auth(user.user) });38 },39 addProgram(user, site_id, program_name) {40 return request(createEndpoint(`/sites/${site_id}/programs`), createRequestOptions(POST, { program_name }, user.user));41 },42 fetchEvents(user, program_id) {43 return request(createEndpoint(`/programs/${program_id}/events`), { headers: auth(user.user) });44 },45 createEvent(user, program_id, season) {46 //debugger;47 const event_date = dates.getTodayDateString();48 const pre_season = season;49 return request(createEndpoint(`/programs/${program_id}/events`), createRequestOptions(POST, {event_date, pre_season}, user.user))50 },51 fetchStudents(user, program_id) {52 return request(createEndpoint(`/programs/${program_id}/students`), { headers: auth(user.user) });53 },54 searchStudent(user, first_name, last_name, dob) {55 return request(createEndpoint(`/students/?first_name=${first_name}&last_name=${last_name}&dob=${dob}`), { headers: auth(user.user) });56 },57 addExistingStudent(user, program_id, student) {58 const student_id = student.student_id,59 first_name = student.first_name,60 last_name = student.last_name,61 dob = student.dob;62 return request(createEndpoint(`/students/${student_id}/programs/${program_id}`), createRequestOptions(PUT, {first_name, last_name, dob}, user.user));63 },64 createStudent(user, program_id, first_name, last_name, dob) {65 return request(createEndpoint(`/programs/${program_id}/students`), createRequestOptions(POST, {first_name, last_name, dob}, user.user));66 },67 fetchStat(user, stat_id) {68 return request(createEndpoint(`/stats/${stat_id}`), { headers: auth(user.user) });69 },70 createStat(user, stat) {71 return request(createEndpoint('/stats'), createRequestOptions(POST, stat, user.user));72 },73 updateStat(user, stat) {74 const statId = stat.stat_id || -1;75 return request(createEndpoint(`/stats/${statId}`), createRequestOptions(PUT, stat, user.user));76 },77 fetchStats(user, program_id) {78 return request(createEndpoint(`/programs/${program_id}/stats`), { headers: auth(user.user) });79 },80 saveCollectedBmiData(user, event_id, stats) {81 return request(createEndpoint(`/events/${event_id}/stats/bmi`), createRequestOptions(PUT, {stats}, user));82 },83 createAccount(email, username, password, first_name, last_name,acct_type) {84 return request(createEndpoint(`/accounts`), createRequestOptions(POST, {email, username, password, first_name, last_name,acct_type}));85 },86 //saves the pacer result for each student87 //TODO is the pacer page consistent with one event_id? how does it input each student's pacer?88 savePacerData(user, event_id, stats) {89 return request(createEndpoint(`/events/${event_id}/stats/pacer`), createRequestOptions(PUT, {stats}, user.user));90 },91};...

Full Screen

Full Screen

requestOptions.spec.js

Source:requestOptions.spec.js Github

copy

Full Screen

...3const btoa = require('btoa')4describe('Method', () => {5 it('should default to GET', () => {6 // Defaults to GET7 const request = createRequestOptions()8 expect(request.method).toBe('get')9 })10 it('should respect user-specified method', () => {11 const request = createRequestOptions({ method: 'post' })12 expect(request.method).toBe('post')13 })14})15describe('Content-Type', () => {16 it('should be undefined for GET requests', () => {17 // This creates simple requests that doesn't trigger preflight18 const request = createRequestOptions()19 const headers = request.headers20 expect(headers.get('content-type')).toBe(null)21 })22 it('should be default to application/json for other requests', () => {23 // 'Content-Type' should be set to 'application/json' for any other requests24 const request = createRequestOptions({ method: 'post' })25 const headers = request.headers26 expect(headers.get('content-type')).toBe('application/json')27 })28 it('should respect user-specified content type', () => {29 // Should request user-created 'Content-Type'30 const request = createRequestOptions({31 headers: { 'Content-Type': 'application/x-www-form-urlencoded' }32 })33 const headers = request.headers34 expect(headers.get('content-type')).toMatch(/x-www-form-urlencoded/)35 })36})37describe('Basic Auth', () => {38 it('Happy path', () => {39 const request = createRequestOptions({40 auth: { username: 'username', password: 'password' }41 })42 const auth = request.headers.get('authorization')43 const encoded = auth.split(' ')[1]44 expect(auth).toMatch(/Basic/)45 expect(encoded).toBe(btoa('username:password'))46 })47 it('Fails without username', () => {48 try {49 createRequestOptions({ auth: { password: 'password' } })50 } catch (error) {51 expect(error.message).toMatch(/Username required/)52 }53 })54 it('Fails without password', () => {55 try {56 createRequestOptions({ auth: { username: 'username' } })57 } catch (error) {58 expect(error.message).toMatch(/Password required/)59 }60 })61})62describe('Bearer Auth', () => {63 it('Happy path', () => {64 // Bearer Auth Headers65 const request = createRequestOptions({ auth: 'token' })66 const auth = request.headers.get('authorization')67 const token = auth.split(' ')[1]68 expect(auth).toMatch(/Bearer/)69 expect(token).toBe(token)70 })71})72describe('Body', () => {73 it('Should be undefined for GET requests', async () => {74 // This prevents preflight requests75 const request = createRequestOptions()76 expect(request.body).toBe(undefined)77 })78 it('Should be JSON format for JSON requests', async () => {79 const request = createRequestOptions({80 method: 'post',81 body: { message: 'Good game' }82 })83 expect(request.body).toBe(JSON.stringify({ message: 'Good game' }))84 })85 it('Should remain raw for JSON x-www-form-urlencoded requests', async () => {86 const request = createRequestOptions({87 method: 'post',88 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },89 body: { message: 'Good game' }90 })91 expect(request.body).toBe('message=Good%20game')92 })...

Full Screen

Full Screen

http.d.ts

Source:http.d.ts Github

copy

Full Screen

1declare namespace HTTP {2 interface Response<T = Object> {3 data: T;4 error: string;5 timeOut: boolean;6 response: {7 status: number;8 localizedStatus: string;9 headerFields: PlainObject10 }11 }12 type ResultType = 'text' | 'json' | 'plist' | 'binary';13 type BodyType = ResultType;14 interface CreateRequestOptions {15 timeout?: number;16 headerFields?: PlainObject;17 method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'UPDATE' | 'HEAD' | 'PATCH';18 body?: string | PlainObject | BinaryData;19 bodyType?: BodyType;20 bodyTextEncoding?: string;21 bodyJSONPrettyPrint?: boolean;22 bodyPlistFormat?: 'xml' | 'binary';23 resultType?: ResultType24 }25 function get<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;26 function getJSON<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;27 function getPlist<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;28 function getData<T = any> (url: string, options?: CreateRequestOptions): HTTP.Response<T>;29 function post<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;30 function postJSON<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;31 function postPlist<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;32 function postData<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;33 interface Request {};34 function createGetRequest(url: string, options?: CreateRequestOptions): HTTP.Request;35 function createGetJSONRequest(url: string, options?: CreateRequestOptions): HTTP.Request;36 function createGetPlistRequest(url: string, options?: CreateRequestOptions): HTTP.Request;37 function createGetDataRequest(url: string, options?: CreateRequestOptions): HTTP.Request;38 function createPostRequest(url: string, options?: CreateRequestOptions): HTTP.Request;39 function createPostJSONRequest(url: string, options?: CreateRequestOptions): HTTP.Request;40 function createPostPlistRequest(url: string, options?: CreateRequestOptions): HTTP.Request;41 function createPostDataRequest(url: string, options?: CreateRequestOptions): HTTP.Request;42 function createRequest(url: string, options?: CreateRequestOptions): HTTP.Request;43 function loadRequest<T = any>(request: HTTP.Request): HTTP.Response<T>;44 function loadRequest<T = any>(url: string, options?: CreateRequestOptions): HTTP.Response<T>;45 function loadRequests<T = any>(requests: HTTP.Request[]): HTTP.Response<T>;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt-api');2const options = wpt.createRequestOptions({3});4wpt.createTest(options, (err, data) => {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11wpt.getTestResults('191205_R_2d9d2e1c1b7a0b8d4a4e0d4e4b4a4b8d', (err, data) => {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18wpt.getTestStatus('191205_R_2d9d2e1c1b7a0b8d4a4e0d4e4b4a4b8d', (err, data) => {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25wpt.getTestResults('191205_R_2d9d2e1c1b7a0b8d4a4e0d4e4b4a4b8d', (err, data) => {26 if (err) {27 console.log(err);28 } else {29 console.log(data);30 }31});32wpt.getTestResults('191205_R_2d9d2e1c1b7a0b8d4a4e0d4e4b4a4b8d', (err, data) => {33 if (err) {34 console.log(err);35 } else {36 console.log(data);37 }38});39wpt.getTestResults('191205_R_2d9d2e1c1b7a0b8d4a4

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2console.log(options);3var wpt = require('wpt-api');4console.log(options);5var wpt = require('wpt-api');6console.log(options);7var wpt = require('wpt-api');8console.log(options);9var wpt = require('wpt-api');10console.log(options);11var wpt = require('wpt-api');12console.log(options);13var wpt = require('wpt-api');14console.log(options);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2console.log(options);3var wpt = require('wpt-api');4console.log(options);5var wpt = require('wpt-api');6console.log(options);7var wpt = require('wpt-api');8console.log(options);9var wpt = require('wpt-api');10console.log(options);11var wpt = require('wpt

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptApiService = require('wpt-api-service');2console.log(options);3const wptApiService = require('wpt-api-service');4console.log(options);5const wptApiService = require('wpt-api-service');6console.log(options);

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