export const checkNavbarLoaded = ( ) => { cy . get ( "nav" ) . should ( "contain" , "CS 2500" ) ; cy . get ( "nav" ) . should ( "contain" , "Schedule" ) ; } ; export const getId = ( id ) => { if ( ! id ) { return cy . wrap ( ) ; } else if ( typeof id == "number" ) { return cy . wrap ( id ) ; } else { return accessAttributes ( id ) ; } } ; export const accessAttributes = ( str ) => { const arr = str . split ( "." ) ; const primaryObj = arr . shift ( ) ; return cy . get ( `@${ primaryObj }` ) . then ( ( obj ) => arr . reduce ( ( data , attr ) => data [ attr ] , obj ) ) ; } ; const makeRequest = ( request , identifier , { ... params } ) => { if ( identifier ) { request ( params ) . then ( ( res ) => res . body ) . as ( identifier ) ; } else { request ( params ) ; } } ; param { string } identifier export const loginUser = ( identifier ) => { cy . get ( `@${ identifier }` ) . then ( ( userCourse ) => { cy . visit ( `/api/v1/login/dev?userId=${ userCourse . user . id }` ) ; cy . url ( ) . should ( "include" , "today" ) ; } ) ; } ; param { string } role param { stirng } courseId param { string } identifier const createUserAndLogin = ( { role , courseId , identifier } ) => { const req = ( parsedId ) => { cy . request ( "POST" , "/api/v1/seeds/createUser" , { role : role , courseId : parsedId } ) . then ( ( res ) => res . body ) . then ( ( userCourse ) => { cy . visit ( `/api/v1/login/dev?userId=${ userCourse . user . id }` ) ; cy . visit ( `/course/${ userCourse . courseId }/today` ) ; cy . getCookie ( "auth_token" ) . then ( ( auth_token ) => ( { ... userCourse , auth_token : auth_token . value } ) ) . as ( identifier ) ; } ) ; } ; if ( courseId ) { getId ( courseId ) . then ( ( courseId ) => req ( courseId ) ) ; } else { req ( ) ; } } ; param { number } courseId param { string } identifier export const createAndLoginTA = ( { courseId = null , identifier = "ta" } = { } ) => createUserAndLogin ( { role : "ta" , courseId , identifier } ) ; param { number } courseId param { string } identifier export const createAndLoginStudent = ( { courseId = null , identifier = "student" , } = { } ) => createUserAndLogin ( { role : "student" , courseId , identifier } ) ; param { number } courseId param { string } identifier export const createAndLoginProfessor = ( { courseId = null , identifier = "professor" , } = { } ) => createUserAndLogin ( { role : "professor" , courseId , identifier } ) ; param { number } courseId param { number } room param { booelan } allowQuestions param { number } closesIn param { string } identifier export const createQueue = ( { courseId = null , room = "Online" , allowQuestions = true , closesIn = 4500000 , identifier = "queue" , } ) => { const req = ( { id } ) => cy . request ( "POST" , "/api/v1/seeds/createQueue" , { courseId : id , room , closesIn , allowQuestions } ) ; getId ( courseId ) . then ( ( id ) => { makeRequest ( req , identifier , { id } ) ; } ) ; } ; export const createQueueWithoutOfficeHour = ( { courseId = null , allowQuestions = true , room = "Online" , } ) => { const req = ( { id } ) => cy . request ( "POST" , "/api/v1/seeds/createQueueWithoutOfficeHour" , { courseId : id , room , allowQuestions } ) ; getId ( courseId ) . then ( ( id ) => { makeRequest ( req , "queue" , { id } ) ; } ) ; } ; param { number } queueId param { number } studentId param { any } data param { string } identifier export const createQuestion = ( { queueId , studentId , data , identifier } ) => { const req = ( { queueId , studentId } ) => cy . request ( "POST" , "/api/v1/seeds/createQuestion" , { studentId , queueId , data } ) ; getId ( queueId ) . then ( ( queueId ) => { getId ( studentId ) . then ( ( studentId ) => makeRequest ( req , identifier , { queueId , studentId } ) ) ; } ) ; } ; param { string } queue param { string } ta export const checkInTA = ( { ta = "ta" , queue = "queue" } = { } ) => { cy . get ( `@${ ta }` ) . then ( ( ta ) => { cy . get ( `@${ queue }` ) . then ( ( queue ) => { cy . request ( { method : "POST" , url : `/api/v1/courses/${ queue . courseId }/ta_location/${ queue . room }` , headers : { Cookie : `auth_token=${ ta . auth_token }` } } ) ; } ) ; } ) ; } ; param { number } id export const helpQuestionWithID = ( id ) => { cy . get ( `[data-cy="list-queue"] [data-cy="queue-list-item-${ id }"]` ) . should ( "be.visible" ) . click ( ) ; cy . get ( '[data-cy="help-student"]' ) . click ( ) ; } ;