How to use parsedData method in tracetest

Best JavaScript code snippet using tracetest

dataExportApiSpec.ts

Source:dataExportApiSpec.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2014-2021 Bjoern Kimminich.3 * SPDX-License-Identifier: MIT4 */5import frisby = require('frisby')6const config = require('config')7const path = require('path')8const fs = require('fs')9const jsonHeader = { 'content-type': 'application/json' }10const REST_URL = 'http://localhost:3000/rest'11describe('/rest/user/data-export', () => {12 it('Export data without use of CAPTCHA', () => {13 return frisby.post(REST_URL + '/user/login', {14 headers: jsonHeader,15 body: {16 email: 'bjoern.kimminich@gmail.com',17 password: 'bW9jLmxpYW1nQGhjaW5pbW1pay5ucmVvamI='18 }19 })20 .expect('status', 200)21 .then(({ json: jsonLogin }) => {22 return frisby.post(REST_URL + '/user/data-export', {23 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },24 body: {25 format: '1'26 }27 })28 .expect('status', 200)29 .expect('header', 'content-type', /application\/json/)30 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')31 .then(({ json }) => {32 const parsedData = JSON.parse(json.userData)33 expect(parsedData.username).toBe('bkimminich')34 expect(parsedData.email).toBe('bjoern.kimminich@gmail.com')35 })36 })37 })38 it('Export data when CAPTCHA requested need right answer', () => {39 return frisby.post(REST_URL + '/user/login', {40 headers: jsonHeader,41 body: {42 email: 'bjoern.kimminich@gmail.com',43 password: 'bW9jLmxpYW1nQGhjaW5pbW1pay5ucmVvamI='44 }45 })46 .expect('status', 200)47 .then(({ json: jsonLogin }) => {48 return frisby.get(REST_URL + '/image-captcha', {49 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }50 })51 .expect('status', 200)52 .expect('header', 'content-type', /application\/json/)53 .then(() => {54 return frisby.post(REST_URL + '/user/data-export', {55 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },56 body: {57 answer: 'AAAAAA',58 format: 159 }60 })61 .expect('status', 401)62 .expect('bodyContains', 'Wrong answer to CAPTCHA. Please try again.')63 })64 })65 })66 it('Export data using right answer to CAPTCHA', () => {67 return frisby.post(REST_URL + '/user/login', {68 headers: jsonHeader,69 body: {70 email: 'bjoern.kimminich@gmail.com',71 password: 'bW9jLmxpYW1nQGhjaW5pbW1pay5ucmVvamI='72 }73 })74 .expect('status', 200)75 .then(({ json: jsonLogin }) => {76 return frisby.get(REST_URL + '/image-captcha', {77 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }78 })79 .expect('status', 200)80 .expect('header', 'content-type', /application\/json/)81 .then(({ json: captchaAnswer }) => {82 return frisby.post(REST_URL + '/user/data-export', {83 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },84 body: {85 answer: captchaAnswer.answer,86 format: 187 }88 })89 .expect('status', 200)90 .expect('header', 'content-type', /application\/json/)91 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')92 .then(({ json }) => {93 const parsedData = JSON.parse(json.userData)94 expect(parsedData.username).toBe('bkimminich')95 expect(parsedData.email).toBe('bjoern.kimminich@gmail.com')96 })97 })98 })99 })100 it('Export data including orders without use of CAPTCHA', () => {101 return frisby.post(REST_URL + '/user/login', {102 headers: jsonHeader,103 body: {104 email: 'amy@' + config.get('application.domain'),105 password: 'K1f.....................'106 }107 })108 .expect('status', 200)109 .then(({ json: jsonLogin }) => {110 return frisby.post(REST_URL + '/basket/4/checkout', {111 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }112 })113 .expect('status', 200)114 .then(() => {115 return frisby.post(REST_URL + '/user/data-export', {116 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },117 body: {118 format: '1'119 }120 })121 .expect('status', 200)122 .expect('header', 'content-type', /application\/json/)123 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')124 .then(({ json }) => {125 const parsedData = JSON.parse(json.userData)126 expect(parsedData.username).toBe('')127 expect(parsedData.email).toBe('amy@' + config.get('application.domain'))128 expect(parsedData.orders[0].totalPrice).toBe(9.98)129 expect(parsedData.orders[0].bonus).toBe(0)130 expect(parsedData.orders[0].products[0].quantity).toBe(2)131 expect(parsedData.orders[0].products[0].name).toBe('Raspberry Juice (1000ml)')132 expect(parsedData.orders[0].products[0].price).toBe(4.99)133 expect(parsedData.orders[0].products[0].total).toBe(9.98)134 expect(parsedData.orders[0].products[0].bonus).toBe(0)135 })136 })137 })138 })139 it('Export data including reviews without use of CAPTCHA', () => {140 return frisby.post(REST_URL + '/user/login', {141 headers: jsonHeader,142 body: {143 email: 'jim@' + config.get('application.domain'),144 password: 'ncc-1701'145 }146 })147 .expect('status', 200)148 .then(({ json: jsonLogin }) => {149 return frisby.post(REST_URL + '/user/data-export', {150 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },151 body: {152 format: '1'153 }154 })155 .expect('status', 200)156 .expect('header', 'content-type', /application\/json/)157 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')158 .then(({ json }) => {159 const parsedData = JSON.parse(json.userData)160 expect(parsedData.username).toBe('')161 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))162 expect(parsedData.reviews[0].message).toBe('Looks so much better on my uniform than the boring Starfleet symbol.')163 expect(parsedData.reviews[0].author).toBe('jim@' + config.get('application.domain'))164 expect(parsedData.reviews[0].productId).toBe(20)165 expect(parsedData.reviews[0].likesCount).toBe(0)166 expect(parsedData.reviews[0].likedBy[0]).toBe(undefined)167 expect(parsedData.reviews[1].message).toBe('Fresh out of a replicator.')168 expect(parsedData.reviews[1].author).toBe('jim@' + config.get('application.domain'))169 expect(parsedData.reviews[1].productId).toBe(22)170 expect(parsedData.reviews[1].likesCount).toBe(0)171 expect(parsedData.reviews[1].likedBy[0]).toBe(undefined)172 })173 })174 })175 it('Export data including memories without use of CAPTCHA', () => {176 const file = path.resolve(__dirname, '../files/validProfileImage.jpg')177 const form = frisby.formData()178 form.append('image', fs.createReadStream(file), 'Valid Image')179 form.append('caption', 'Valid Image')180 return frisby.post(REST_URL + '/user/login', {181 headers: jsonHeader,182 body: {183 email: 'jim@' + config.get('application.domain'),184 password: 'ncc-1701'185 }186 })187 .expect('status', 200)188 .then(({ json: jsonLogin }) => {189 return frisby.post(REST_URL + '/memories', {190 headers: {191 Authorization: 'Bearer ' + jsonLogin.authentication.token,192 'Content-Type': form.getHeaders()['content-type']193 },194 body: form195 })196 .expect('status', 200)197 .then(() => {198 return frisby.post(REST_URL + '/user/data-export', {199 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },200 body: {201 format: '1'202 }203 })204 .expect('status', 200)205 .expect('header', 'content-type', /application\/json/)206 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')207 .then(({ json }) => {208 const parsedData = JSON.parse(json.userData)209 expect(parsedData.username).toBe('')210 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))211 expect(parsedData.memories[0].caption).toBe('Valid Image')212 expect(parsedData.memories[0].imageUrl).toContain('assets/public/images/uploads/valid-image')213 })214 })215 })216 })217 it('Export data including orders with use of CAPTCHA', () => {218 return frisby.post(REST_URL + '/user/login', {219 headers: jsonHeader,220 body: {221 email: 'amy@' + config.get('application.domain'),222 password: 'K1f.....................'223 }224 })225 .expect('status', 200)226 .then(({ json: jsonLogin }) => {227 return frisby.post(REST_URL + '/basket/4/checkout', {228 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }229 })230 .expect('status', 200)231 .then(() => {232 return frisby.get(REST_URL + '/image-captcha', {233 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }234 })235 .expect('status', 200)236 .expect('header', 'content-type', /application\/json/)237 .then(({ json: captchaAnswer }) => {238 return frisby.post(REST_URL + '/user/data-export', {239 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },240 body: {241 answer: captchaAnswer.answer,242 format: 1243 }244 })245 .expect('status', 200)246 .expect('header', 'content-type', /application\/json/)247 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')248 .then(({ json }) => {249 const parsedData = JSON.parse(json.userData)250 expect(parsedData.username).toBe('')251 expect(parsedData.email).toBe('amy@' + config.get('application.domain'))252 expect(parsedData.orders[0].totalPrice).toBe(9.98)253 expect(parsedData.orders[0].bonus).toBe(0)254 expect(parsedData.orders[0].products[0].quantity).toBe(2)255 expect(parsedData.orders[0].products[0].name).toBe('Raspberry Juice (1000ml)')256 expect(parsedData.orders[0].products[0].price).toBe(4.99)257 expect(parsedData.orders[0].products[0].total).toBe(9.98)258 expect(parsedData.orders[0].products[0].bonus).toBe(0)259 })260 })261 })262 })263 })264 it('Export data including reviews with use of CAPTCHA', () => {265 return frisby.post(REST_URL + '/user/login', {266 headers: jsonHeader,267 body: {268 email: 'jim@' + config.get('application.domain'),269 password: 'ncc-1701'270 }271 })272 .expect('status', 200)273 .then(({ json: jsonLogin }) => {274 return frisby.get(REST_URL + '/image-captcha', {275 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }276 })277 .expect('status', 200)278 .expect('header', 'content-type', /application\/json/)279 .then(({ json: captchaAnswer }) => {280 return frisby.post(REST_URL + '/user/data-export', {281 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },282 body: {283 answer: captchaAnswer.answer,284 format: 1285 }286 })287 .expect('status', 200)288 .expect('header', 'content-type', /application\/json/)289 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')290 .then(({ json }) => {291 const parsedData = JSON.parse(json.userData)292 expect(parsedData.username).toBe('')293 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))294 expect(parsedData.reviews[0].message).toBe('Looks so much better on my uniform than the boring Starfleet symbol.')295 expect(parsedData.reviews[0].author).toBe('jim@' + config.get('application.domain'))296 expect(parsedData.reviews[0].productId).toBe(20)297 expect(parsedData.reviews[0].likesCount).toBe(0)298 expect(parsedData.reviews[0].likedBy[0]).toBe(undefined)299 expect(parsedData.reviews[1].message).toBe('Fresh out of a replicator.')300 expect(parsedData.reviews[1].author).toBe('jim@' + config.get('application.domain'))301 expect(parsedData.reviews[1].productId).toBe(22)302 expect(parsedData.reviews[1].likesCount).toBe(0)303 expect(parsedData.reviews[1].likedBy[0]).toBe(undefined)304 })305 })306 })307 })308 it('Export data including memories with use of CAPTCHA', () => {309 const file = path.resolve(__dirname, '../files/validProfileImage.jpg')310 const form = frisby.formData()311 form.append('image', fs.createReadStream(file), 'Valid Image')312 form.append('caption', 'Valid Image')313 return frisby.post(REST_URL + '/user/login', {314 headers: jsonHeader,315 body: {316 email: 'jim@' + config.get('application.domain'),317 password: 'ncc-1701'318 }319 })320 .expect('status', 200)321 .then(({ json: jsonLogin }) => {322 return frisby.post(REST_URL + '/memories', {323 headers: {324 Authorization: 'Bearer ' + jsonLogin.authentication.token,325 'Content-Type': form.getHeaders()['content-type']326 },327 body: form328 })329 .expect('status', 200)330 .then(() => {331 return frisby.get(REST_URL + '/image-captcha', {332 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }333 })334 .expect('status', 200)335 .expect('header', 'content-type', /application\/json/)336 .then(({ json: captchaAnswer }) => {337 return frisby.post(REST_URL + '/user/data-export', {338 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },339 body: {340 answer: captchaAnswer.answer,341 format: 1342 }343 })344 .expect('status', 200)345 .expect('header', 'content-type', /application\/json/)346 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')347 .then(({ json }) => {348 const parsedData = JSON.parse(json.userData)349 expect(parsedData.username).toBe('')350 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))351 expect(parsedData.memories[0].caption).toBe('Valid Image')352 expect(parsedData.memories[0].imageUrl).toContain('assets/public/images/uploads/valid-image')353 })354 })355 })356 })357 })...

Full Screen

Full Screen

dataExportApiSpec.js

Source:dataExportApiSpec.js Github

copy

Full Screen

1/*2 * Copyright (c) 2014-2020 Bjoern Kimminich.3 * SPDX-License-Identifier: MIT4 */5const frisby = require('frisby')6const config = require('config')7const path = require('path')8const fs = require('fs')9const jsonHeader = { 'content-type': 'application/json' }10const REST_URL = 'http://localhost:3000/rest'11describe('/rest/user/data-export', () => {12 it('Export data without use of CAPTCHA', () => {13 return frisby.post(REST_URL + '/user/login', {14 headers: jsonHeader,15 body: {16 email: 'bjoern.kimminich@gmail.com',17 password: 'bW9jLmxpYW1nQGhjaW5pbW1pay5ucmVvamI='18 }19 })20 .expect('status', 200)21 .then(({ json: jsonLogin }) => {22 return frisby.post(REST_URL + '/user/data-export', {23 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },24 body: {25 format: '1'26 }27 })28 .expect('status', 200)29 .expect('header', 'content-type', /application\/json/)30 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')31 .then(({ json }) => {32 const parsedData = JSON.parse(json.userData)33 expect(parsedData.username).toBe('bkimminich')34 expect(parsedData.email).toBe('bjoern.kimminich@gmail.com')35 })36 })37 })38 it('Export data when CAPTCHA requested need right answer', () => {39 return frisby.post(REST_URL + '/user/login', {40 headers: jsonHeader,41 body: {42 email: 'bjoern.kimminich@gmail.com',43 password: 'bW9jLmxpYW1nQGhjaW5pbW1pay5ucmVvamI='44 }45 })46 .expect('status', 200)47 .then(({ json: jsonLogin }) => {48 return frisby.get(REST_URL + '/image-captcha', {49 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }50 })51 .expect('status', 200)52 .expect('header', 'content-type', /application\/json/)53 .then(() => {54 return frisby.post(REST_URL + '/user/data-export', {55 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },56 body: {57 answer: 'AAAAAA',58 format: 159 }60 })61 .expect('status', 401)62 .expect('bodyContains', 'Wrong answer to CAPTCHA. Please try again.')63 })64 })65 })66 it('Export data using right answer to CAPTCHA', () => {67 return frisby.post(REST_URL + '/user/login', {68 headers: jsonHeader,69 body: {70 email: 'bjoern.kimminich@gmail.com',71 password: 'bW9jLmxpYW1nQGhjaW5pbW1pay5ucmVvamI='72 }73 })74 .expect('status', 200)75 .then(({ json: jsonLogin }) => {76 return frisby.get(REST_URL + '/image-captcha', {77 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }78 })79 .expect('status', 200)80 .expect('header', 'content-type', /application\/json/)81 .then(({ json: captchaAnswer }) => {82 return frisby.post(REST_URL + '/user/data-export', {83 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },84 body: {85 answer: captchaAnswer.answer,86 format: 187 }88 })89 .expect('status', 200)90 .expect('header', 'content-type', /application\/json/)91 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')92 .then(({ json }) => {93 const parsedData = JSON.parse(json.userData)94 expect(parsedData.username).toBe('bkimminich')95 expect(parsedData.email).toBe('bjoern.kimminich@gmail.com')96 })97 })98 })99 })100 it('Export data including orders without use of CAPTCHA', () => {101 return frisby.post(REST_URL + '/user/login', {102 headers: jsonHeader,103 body: {104 email: 'amy@' + config.get('application.domain'),105 password: 'K1f.....................'106 }107 })108 .expect('status', 200)109 .then(({ json: jsonLogin }) => {110 return frisby.post(REST_URL + '/basket/4/checkout', {111 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }112 })113 .expect('status', 200)114 .then(() => {115 return frisby.post(REST_URL + '/user/data-export', {116 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },117 body: {118 format: '1'119 }120 })121 .expect('status', 200)122 .expect('header', 'content-type', /application\/json/)123 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')124 .then(({ json }) => {125 const parsedData = JSON.parse(json.userData)126 expect(parsedData.username).toBe('')127 expect(parsedData.email).toBe('amy@' + config.get('application.domain'))128 expect(parsedData.orders[0].totalPrice).toBe(9.98)129 expect(parsedData.orders[0].bonus).toBe(0)130 expect(parsedData.orders[0].products[0].quantity).toBe(2)131 expect(parsedData.orders[0].products[0].name).toBe('Raspberry Juice (1000ml)')132 expect(parsedData.orders[0].products[0].price).toBe(4.99)133 expect(parsedData.orders[0].products[0].total).toBe(9.98)134 expect(parsedData.orders[0].products[0].bonus).toBe(0)135 })136 })137 })138 })139 it('Export data including reviews without use of CAPTCHA', () => {140 return frisby.post(REST_URL + '/user/login', {141 headers: jsonHeader,142 body: {143 email: 'jim@' + config.get('application.domain'),144 password: 'ncc-1701'145 }146 })147 .expect('status', 200)148 .then(({ json: jsonLogin }) => {149 return frisby.post(REST_URL + '/user/data-export', {150 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },151 body: {152 format: '1'153 }154 })155 .expect('status', 200)156 .expect('header', 'content-type', /application\/json/)157 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')158 .then(({ json }) => {159 const parsedData = JSON.parse(json.userData)160 expect(parsedData.username).toBe('')161 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))162 expect(parsedData.reviews[0].message).toBe('Looks so much better on my uniform than the boring Starfleet symbol.')163 expect(parsedData.reviews[0].author).toBe('jim@' + config.get('application.domain'))164 expect(parsedData.reviews[0].productId).toBe(20)165 expect(parsedData.reviews[0].likesCount).toBe(0)166 expect(parsedData.reviews[0].likedBy[0]).toBe(undefined)167 expect(parsedData.reviews[1].message).toBe('Fresh out of a replicator.')168 expect(parsedData.reviews[1].author).toBe('jim@' + config.get('application.domain'))169 expect(parsedData.reviews[1].productId).toBe(22)170 expect(parsedData.reviews[1].likesCount).toBe(0)171 expect(parsedData.reviews[1].likedBy[0]).toBe(undefined)172 })173 })174 })175 it('Export data including memories without use of CAPTCHA', () => {176 const file = path.resolve(__dirname, '../files/validProfileImage.jpg')177 const form = frisby.formData()178 form.append('image', fs.createReadStream(file), 'Valid Image')179 form.append('caption', 'Valid Image')180 return frisby.post(REST_URL + '/user/login', {181 headers: jsonHeader,182 body: {183 email: 'jim@' + config.get('application.domain'),184 password: 'ncc-1701'185 }186 })187 .expect('status', 200)188 .then(({ json: jsonLogin }) => {189 return frisby.post(REST_URL + '/memories', {190 headers: {191 Authorization: 'Bearer ' + jsonLogin.authentication.token,192 'Content-Type': form.getHeaders()['content-type']193 },194 body: form195 })196 .expect('status', 200)197 .then(() => {198 return frisby.post(REST_URL + '/user/data-export', {199 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },200 body: {201 format: '1'202 }203 })204 .expect('status', 200)205 .expect('header', 'content-type', /application\/json/)206 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')207 .then(({ json }) => {208 const parsedData = JSON.parse(json.userData)209 expect(parsedData.username).toBe('')210 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))211 expect(parsedData.memories[0].caption).toBe('Valid Image')212 expect(parsedData.memories[0].imageUrl).toContain('assets/public/images/uploads/valid-image')213 })214 })215 })216 })217 it('Export data including orders with use of CAPTCHA', () => {218 return frisby.post(REST_URL + '/user/login', {219 headers: jsonHeader,220 body: {221 email: 'amy@' + config.get('application.domain'),222 password: 'K1f.....................'223 }224 })225 .expect('status', 200)226 .then(({ json: jsonLogin }) => {227 return frisby.post(REST_URL + '/basket/4/checkout', {228 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }229 })230 .expect('status', 200)231 .then(() => {232 return frisby.get(REST_URL + '/image-captcha', {233 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }234 })235 .expect('status', 200)236 .expect('header', 'content-type', /application\/json/)237 .then(({ json: captchaAnswer }) => {238 return frisby.post(REST_URL + '/user/data-export', {239 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },240 body: {241 answer: captchaAnswer.answer,242 format: 1243 }244 })245 .expect('status', 200)246 .expect('header', 'content-type', /application\/json/)247 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')248 .then(({ json }) => {249 const parsedData = JSON.parse(json.userData)250 expect(parsedData.username).toBe('')251 expect(parsedData.email).toBe('amy@' + config.get('application.domain'))252 expect(parsedData.orders[0].totalPrice).toBe(9.98)253 expect(parsedData.orders[0].bonus).toBe(0)254 expect(parsedData.orders[0].products[0].quantity).toBe(2)255 expect(parsedData.orders[0].products[0].name).toBe('Raspberry Juice (1000ml)')256 expect(parsedData.orders[0].products[0].price).toBe(4.99)257 expect(parsedData.orders[0].products[0].total).toBe(9.98)258 expect(parsedData.orders[0].products[0].bonus).toBe(0)259 })260 })261 })262 })263 })264 it('Export data including reviews with use of CAPTCHA', () => {265 return frisby.post(REST_URL + '/user/login', {266 headers: jsonHeader,267 body: {268 email: 'jim@' + config.get('application.domain'),269 password: 'ncc-1701'270 }271 })272 .expect('status', 200)273 .then(({ json: jsonLogin }) => {274 return frisby.get(REST_URL + '/image-captcha', {275 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }276 })277 .expect('status', 200)278 .expect('header', 'content-type', /application\/json/)279 .then(({ json: captchaAnswer }) => {280 return frisby.post(REST_URL + '/user/data-export', {281 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },282 body: {283 answer: captchaAnswer.answer,284 format: 1285 }286 })287 .expect('status', 200)288 .expect('header', 'content-type', /application\/json/)289 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')290 .then(({ json }) => {291 const parsedData = JSON.parse(json.userData)292 expect(parsedData.username).toBe('')293 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))294 expect(parsedData.reviews[0].message).toBe('Looks so much better on my uniform than the boring Starfleet symbol.')295 expect(parsedData.reviews[0].author).toBe('jim@' + config.get('application.domain'))296 expect(parsedData.reviews[0].productId).toBe(20)297 expect(parsedData.reviews[0].likesCount).toBe(0)298 expect(parsedData.reviews[0].likedBy[0]).toBe(undefined)299 expect(parsedData.reviews[1].message).toBe('Fresh out of a replicator.')300 expect(parsedData.reviews[1].author).toBe('jim@' + config.get('application.domain'))301 expect(parsedData.reviews[1].productId).toBe(22)302 expect(parsedData.reviews[1].likesCount).toBe(0)303 expect(parsedData.reviews[1].likedBy[0]).toBe(undefined)304 })305 })306 })307 })308 it('Export data including memories with use of CAPTCHA', () => {309 const file = path.resolve(__dirname, '../files/validProfileImage.jpg')310 const form = frisby.formData()311 form.append('image', fs.createReadStream(file), 'Valid Image')312 form.append('caption', 'Valid Image')313 return frisby.post(REST_URL + '/user/login', {314 headers: jsonHeader,315 body: {316 email: 'jim@' + config.get('application.domain'),317 password: 'ncc-1701'318 }319 })320 .expect('status', 200)321 .then(({ json: jsonLogin }) => {322 return frisby.post(REST_URL + '/memories', {323 headers: {324 Authorization: 'Bearer ' + jsonLogin.authentication.token,325 'Content-Type': form.getHeaders()['content-type']326 },327 body: form328 })329 .expect('status', 200)330 .then(() => {331 return frisby.get(REST_URL + '/image-captcha', {332 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' }333 })334 .expect('status', 200)335 .expect('header', 'content-type', /application\/json/)336 .then(({ json: captchaAnswer }) => {337 return frisby.post(REST_URL + '/user/data-export', {338 headers: { Authorization: 'Bearer ' + jsonLogin.authentication.token, 'content-type': 'application/json' },339 body: {340 answer: captchaAnswer.answer,341 format: 1342 }343 })344 .expect('status', 200)345 .expect('header', 'content-type', /application\/json/)346 .expect('json', 'confirmation', 'Your data export will open in a new Browser window.')347 .then(({ json }) => {348 const parsedData = JSON.parse(json.userData)349 expect(parsedData.username).toBe('')350 expect(parsedData.email).toBe('jim@' + config.get('application.domain'))351 expect(parsedData.memories[0].caption).toBe('Valid Image')352 expect(parsedData.memories[0].imageUrl).toContain('assets/public/images/uploads/valid-image')353 })354 })355 })356 })357 })...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const fs = require("fs")2fs.readFile('./DataToConvert.json', 'utf8', (err, jsonString) => {3 if (err) {4 console.log("File read failed:", err)5 return6 }7 8 var parsedData = JSON.parse(jsonString)9 // Deletes old properties10 delete parsedData.activityConfigs11 delete parsedData.categoryConfigs12 delete parsedData.indexNotes13 delete parsedData.noteIndices14 delete parsedData.weeks15 delete parsedData.years16 delete parsedData.yearWeekNumbers17 delete parsedData.yearWeeks18 parsedData["analytics"] = {}19 20 Object.keys(parsedData.categories).forEach(weekid => {21 // Create analytics object for current weekid22 parsedData.analytics[weekid] = {23 categories: {24 25 }, 26 activities: {27 28 }29 } 30 Object.keys(parsedData.categorySettings).forEach(categid => {31 parsedData.analytics[weekid]["categories"][categid] = 032 })33 Object.keys(parsedData.activitySettings).forEach(actid => {34 parsedData.analytics[weekid]["activities"][actid] = 035 })36 console.log(parsedData.analytics)37 for (var i = 0; i < 96*7; i++) { // Iterates over all 15 minute intervals in a week38 // Deletes unnecessary properties39 delete parsedData.categories[weekid][i].short40 delete parsedData.categories[weekid][i].long41 if (parsedData.categories[weekid][i].categoryid !== "") { // If there is a category in this in interval42 var categoryid = parsedData.categories[weekid][i].categoryid // Gets the categoryid43 if (!parsedData["analytics"][weekid]["categories"][categoryid]) { // If this categoryid isn't yet in the analytics object44 45 parsedData["analytics"][weekid]["categories"][categoryid] = 1 // Initialise this categoryid in analytics object with 146 } else { // If this categoryid is already in the analytics object47 48 var categCount = parseInt(parsedData["analytics"][weekid]["categories"][categoryid]) // Gets the current count for the categoryid and converts it to int49 categCount += 1 // Increment the current categery count by 150 parsedData["analytics"][weekid]["categories"][categoryid] = categCount // Set the new category count 51 }52 }53 if (parsedData.categories[weekid][i].activityid !== "") { // If there is an activity in this in interval54 var activityid = parsedData.categories[weekid][i].activityid // Gets the activityid55 56 if (!parsedData["analytics"][weekid]["activities"][activityid]) { // If this activityid isn't yet in the analytics object57 parsedData["analytics"][weekid]["activities"][activityid] = 1 // Initialise this activityid in analytics object with 158 } else { // If this activityid is already in the analytics object59 var activCount = parseInt(parsedData["analytics"][weekid]["activities"][activityid]) // Gets the current count for the activityid and converts it to int60 activCount += 1 // Increment the current activity count by 161 parsedData["analytics"][weekid]["activities"][activityid] = activCount // Set the new activity count 62 }63 }64 }65 })66 67 const jsonStr = JSON.stringify(parsedData)68 69 fs.writeFile('./ConvertedData.json', jsonStr, err => {70 if (err) {71 console.log('Error writing file', err)72 } else {73 console.log('Successfully wrote file')74 }75 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest');2var parsedData = tracetest.parsedData;3console.log(parsedData);4var fs = require('fs');5var parsedData = "";6fs.readFile('trace.txt', 'utf8', function(err, data) {7 if (err) throw err;8 parsedData = data;9 console.log(parsedData);10});11module.exports.parsedData = parsedData;

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest.js');2var trace = tracetest.trace;3var parsedData = tracetest.parsedData;4var tracetest = require('./tracetest.js');5var trace = tracetest.trace;6var parsedData = tracetest.parsedData;7var tracetest = require('./tracetest.js');8var trace = tracetest.trace;9var parsedData = tracetest.parsedData;10var tracetest = require('./tracetest.js');11var trace = tracetest.trace;12var parsedData = tracetest.parsedData;13var tracetest = require('./tracetest.js');14var trace = tracetest.trace;15var parsedData = tracetest.parsedData;16var tracetest = require('./tracetest.js');17var trace = tracetest.trace;18var parsedData = tracetest.parsedData;19var tracetest = require('./tracetest.js');20var trace = tracetest.trace;21var parsedData = tracetest.parsedData;22var tracetest = require('./tracetest.js');23var trace = tracetest.trace;24var parsedData = tracetest.parsedData;25var tracetest = require('./tracetest.js');26var trace = tracetest.trace;27var parsedData = tracetest.parsedData;28var tracetest = require('./tracetest.js');29var trace = tracetest.trace;30var parsedData = tracetest.parsedData;31var tracetest = require('./tracetest.js');32var trace = tracetest.trace;33var parsedData = tracetest.parsedData;34var tracetest = require('./tracetest.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('./tracetest.js');2var parsedData = trace.parsedData();3console.log(parsedData);4var trace = require('./trace.js');5var parsedData = trace.trace();6module.exports.parsedData = function(){7 return parsedData;8}9var trace = require('./trace.js');10var parsedData = trace.trace();11module.exports.parsedData = function(){12 return parsedData;13}14var trace = require('./trace.js');15var parsedData = trace.trace();16module.exports.parsedData = function(){17 return parsedData;18}19var trace = require('./trace.js');20var parsedData = trace.trace();21module.exports.parsedData = function(){22 return parsedData;23}24var trace = require('./trace.js');25var parsedData = trace.trace();26module.exports.parsedData = function(){27 return parsedData;28}29var trace = require('./trace.js');30var parsedData = trace.trace();31module.exports.parsedData = function(){32 return parsedData;33}34var trace = require('./trace.js');35var parsedData = trace.trace();36module.exports.parsedData = function(){37 return parsedData;38}39var trace = require('./trace.js');40var parsedData = trace.trace();41module.exports.parsedData = function(){42 return parsedData;43}44var trace = require('./trace.js');45var parsedData = trace.trace();46module.exports.parsedData = function(){47 return parsedData;48}49var trace = require('./trace.js');50var parsedData = trace.trace();51module.exports.parsedData = function(){52 return parsedData;53}54var trace = require('./trace

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest');2tracetest.parsedData();3exports.parsedData = function(){4 console.log('parsedData method called');5}6console.log('Data parsed');

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('./tracetest');2trace.parsedData();3module.exports.parsedData = function() {4 console.log('parsed data');5};6module.exports.parsedData = function() {7 console.log('parsed data');8};9module.exports.rawData = function() {10 console.log('raw data');11};12module.exports = {13 parsedData: function() {14 console.log('parsed data');15 },16 rawData: function() {17 console.log('raw data');18 }19};20module.exports = function() {21 this.parsedData = function() {22 console.log('parsed data');23 };24 this.rawData = function() {25 console.log('raw data');26 };27};

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