How to use getUserByEmail method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

loadUserJWT.spec.ts

Source:loadUserJWT.spec.ts Github

copy

Full Screen

1import loadUserJWTUnbound from './loadUserJWT.unbound';2import { expect as expectChai } from 'chai';3import { AppError } from 'common/error';4import { Fcn } from 'common/types';5import { NextFunction, RequestHandler } from 'express';6import { TransactionContext } from 'model/sequelize/modelFactory/modelFactory.types';7import { User as UserModel } from 'model/sequelize/model/user/user';8import { UserService } from 'service/sequelize/userService/userService.types';9import { Either } from 'tsmonad';10import { AppRequest } from 'web/serverModules/types';11import { PluginSdkService } from 'service/serviceFactory/serviceFactory.types';12import { InternalServerError, NotAuthorized, NotFound } from 'common/httpErrors';13import { MiddlewareFactory } from '../middlewares.types';14const USERNAME: string = 'joe.doe@company.com';15describe(`Test 'web' module`, () => {16 describe(`common`, () => {17 describe(`middlewares`, () => {18 describe(`load authenticated user`, () => {19 let logError: Fcn<[string], <E>(e: E) => E>;20 let logger: <E>(e: E) => E;21 let userService: UserService = {} as UserService;22 let getUserByEmail: Fcn<[string], Promise<Either<AppError, UserModel>>>;23 let nextFcn: NextFunction;24 let loadUserJWT: MiddlewareFactory<PluginSdkService, RequestHandler>;25 beforeAll(() => {26 logger = jest.fn().mockImplementation(<E> (e: E): E => e);27 logError = jest.fn().mockImplementation((_message: string) => logger);28 nextFcn = jest.fn().mockReturnValue(null);29 loadUserJWT = loadUserJWTUnbound.apply(null, [logError]);30 });31 afterEach(() => {32 jest.clearAllMocks();33 });34 describe('Happy path', () => {35 const USER: UserModel = {} as UserModel;36 let request: AppRequest<unknown, unknown, UserModel> = {37 jwt: {38 preferred_username: USERNAME39 }40 } as AppRequest<unknown, unknown, UserModel>;41 beforeAll(() => {42 getUserByEmail = jest.fn().mockResolvedValue(Either.right<AppError, UserModel>(USER));43 userService.getUserByEmail = jest.fn().mockImplementation((_ctx: TransactionContext): Fcn<[string], Promise<Either<AppError, UserModel>>> => getUserByEmail);44 });45 it(`Should find authenticated user in locla DB and add him in to request`, () => {46 loadUserJWT47 .apply(null, [{ userService }])48 .apply(null, [request, null, nextFcn])49 .then(() => {50 expect(userService.getUserByEmail)51 .toHaveBeenCalledWith();52 expect(getUserByEmail)53 .toHaveBeenCalledWith(USERNAME);54 expect(nextFcn)55 .toHaveBeenCalledWith();56 expect(logError)57 .not.toHaveBeenCalled();58 expectChai(request)59 .to.haveOwnProperty('currentUser')60 .which.is.deep.equal(USER);61 });62 });63 });64 describe('Error path', () => {65 let request: AppRequest<unknown, unknown, UserModel> = {66 jwt: {67 preferred_username: USERNAME68 }69 } as AppRequest<unknown, unknown, UserModel>;70 describe('User not found', () => {71 const ERROR_NOT_FOUND: NotFound = new NotFound('user not found');72 beforeAll(() => {73 getUserByEmail = jest.fn().mockResolvedValue(Either.left<AppError, UserModel>(ERROR_NOT_FOUND));74 userService.getUserByEmail = jest.fn().mockImplementation((_ctx: TransactionContext): Fcn<[string], Promise<Either<AppError, UserModel>>> => getUserByEmail);75 });76 it(`Should log and shift exact error, if user is not found in DB`, () => {77 const expectedError: NotAuthorized = new NotAuthorized(ERROR_NOT_FOUND.message);78 loadUserJWT79 .apply(null, [{ userService }])80 .apply(null, [request, null, nextFcn])81 .then(() => {82 expect(userService.getUserByEmail)83 .toHaveBeenCalledWith();84 expect(getUserByEmail)85 .toHaveBeenCalledWith(USERNAME);86 expect(nextFcn)87 .toHaveBeenCalledWith(expectedError);88 expect(logError)89 .toHaveBeenCalledWith('[AUTHORIZATION]:');90 expect(logger)91 .toHaveBeenCalledWith(expectedError);92 expectChai(request)93 .to.not.haveOwnProperty('currentUser');94 });95 });96 });97 describe('error', () => {98 const ERROR: InternalServerError = new InternalServerError();99 beforeAll(() => {100 getUserByEmail = jest.fn().mockResolvedValue(Either.left<AppError, UserModel>(ERROR));101 userService.getUserByEmail = jest.fn().mockImplementation((_ctx: TransactionContext): Fcn<[string], Promise<Either<AppError, UserModel>>> => getUserByEmail);102 });103 it(`Should log and shift exact error, if user is not found in DB`, () => {104 loadUserJWT105 .apply(null, [{ userService }])106 .apply(null, [request, null, nextFcn])107 .then(() => {108 expect(userService.getUserByEmail)109 .toHaveBeenCalledWith();110 expect(getUserByEmail)111 .toHaveBeenCalledWith(USERNAME);112 expect(nextFcn)113 .toHaveBeenCalledWith(ERROR);114 expect(logError)115 .toHaveBeenCalledWith('[AUTHORIZATION]:');116 expect(logger)117 .toHaveBeenCalledWith(ERROR);118 expectChai(request)119 .to.not.haveOwnProperty('currentUser');120 });121 });122 });123 });124 });125 });126 });...

Full Screen

Full Screen

axios.js

Source:axios.js Github

copy

Full Screen

1const axios= require('axios');2const apiUrl = 'https://3.236.236.86:30000/graphql';3process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';4async function getUserByEmail(email){5 console.log('Axios:');6 console.log(email);7 return await axios.post(apiUrl, {8 query: ` query{9 getUserByEmail(email: "${email.email}"){10 id11 email12 name13 nickname14 image15 }16 }`17 })18 .then((res) => {19 if(res.data.data.getUserByEmail != null && res.status == 200){20 console.log("axios")21 console.log(res.data.data.getUserByEmail)22 let users = {23 id: res.data.data.getUserByEmail.id,24 email: res.data.data.getUserByEmail.email,25 name: res.data.data.getUserByEmail.name,26 nickname: res.data.data.getUserByEmail.nickname,27 image: res.data.data.getUserByEmail.image28 }29 return {users:users};30 }31 else{32 console.log("Usuario no encontrado");33 return "Usuario no encontrado";34 }35 })36 .catch((error) => {37 console.log("No conecta con UnracoonApi")38 console.error(error)39 throw "No conecta con UnracoonApi"40 });41}42/*console.log("el retorno");43console.log(getUserByEmail("elusuariodeprueba2@unal.edu.co"));*/44module.exports = {45 getUserByEmail...

Full Screen

Full Screen

axios_prueba.js

Source:axios_prueba.js Github

copy

Full Screen

1const axios= require('axios');2const apiUrl = 'https://3.236.236.86:30000/graphql';3process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';4async function getUserByEmail(email){5 console.log('Axios:');6 console.log(email);7 return await axios.post(apiUrl, {8 query: ` query{9 getUserByEmail(email: ${email}){10 id11 email12 name13 nickname14 image15 }16 }`17 })18 .then((res) => {19 if(res.data.data.getUserByEmail != null && res.status == 200){20 console.log("axios")21 console.log(res.data.data.getUserByEmail)22 let users = {23 id: res.data.data.getUserByEmail.id,24 email: res.data.data.getUserByEmail.email,25 name: res.data.data.getUserByEmail.name,26 nickname: res.data.data.getUserByEmail.nickname,27 image: res.data.data.getUserByEmail.image28 }29 return {users:users};30 }31 else{32 console.log("Usuario no encontrado");33 return "Usuario no encontrado";34 }35 })36 .catch((error) => {37 console.log("No conecta con UnracoonApi")38 console.error(error)39 throw "No conecta con UnracoonApi"40 });41}42/*console.log("el retorno");43console.log(getUserByEmail("elusuariodeprueba2@unal.edu.co"));*/44module.exports = {45 getUserByEmail...

Full Screen

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 devicefarmer-stf 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