var test = require('tape')
const {handleMessages} = require('././utils')
const canvasApi = require('../../canvasApi')
const randomstring = require('randomstring')

test('should enroll an assistant in an existing course in canvas', t => {
  t.plan(1)
  let canvasCourse

  const courseCode = 'A' + randomstring.generate(5)

  const message = {
    'kthid': 'u2kub9j5',
    'ugClass': 'group',
    'deleted': false,
    'ug1Name': `edu.courses.SF.${courseCode}.20171.1.assistants`,
    'name_en': 'Teacher assistants for SF1625 Spring 17 1',
    'name_sv': 'Lärarassistenter på SF1625 VT17 1',
    'member': ['u1znmoik']}

  const course = {
    'name': 'Emil testar',
    'course_code': courseCode,
    'sis_course_id': `${courseCode}VT171`,
    'start_at': '2016-08-29T09:15:03.346Z'
  }

  // First create a fresch course in canvas
  canvasApi.createCourse({course}, 14) // Courses that starts with an 'A' is handled by account 14
  .then(res => {
    canvasCourse = res
    console.log('canvasCourse', canvasCourse)
  })
  .then(() => handleMessages(message))
  .then(([{resp}]) => canvasApi.pollUntilSisComplete(resp.id))
  .then(() => canvasApi.getEnrollments(canvasCourse.id))
  .then(([enrolledUser]) => {
    t.ok(enrolledUser.sis_user_id === 'u1znmoik')
  })
})

@@ -315,17 +315,47 @@
 rate(5)%0A
+  const userKthId = 'u1znmoik'
 %0A
-
   const 
@@ -630,26 +630,25 @@
 mber': %5B
-'u1znmoik'
+userKthId
 %5D%7D%0A%0A  co
@@ -970,20 +970,16 @@
 res =%3E %7B
-%0A   
  canvasC
@@ -993,56 +993,8 @@
  res
-%0A    console.log('canvasCourse', canvasCourse)%0A 
  %7D)%0A
@@ -1220,26 +1220,25 @@
 _id === 
-'u1znmoik'
+userKthId
 )%0A  %7D)%0A%7D

refactor test