Skip to content
Ryan Christiani edited this page Oct 25, 2017 · 7 revisions

Authentication

All routes require you to be authorized. Make a GET request to /v1/user/authenticate to get your token. Every authenticated route requires a x-access-token header with your token sent.

Available Fields

{
  questions: [QuestionIds],
  course: CourseId
  title: String,
  created_at: Number,
  created_by: String,
  updated_at: Number,
  updated_by: String
}

/v2/tests

GET Return all tests

Headers Value Description
x-access-token : string token Token received from authentication.

Response

{
  "tests": [
    {
      //...
    },
    {
      //...
    },
    {
      //...
    }
  ]
}

/v2/tests/:id

GET Return test by id

Headers Value Description
x-access-token : string token Token received from authentication.
Params Value Description
id : string 564a449a2e55ee5430afb12d ID for test that you want to get.

Response

{
  "test": {
    "title": "HTML/CSS Test",
  }
}

/v2/tests

POST Create a test

Headers Value Description
x-access-token : string token Token received from authentication.
Query Value Description
courseId : string 564a449a2e55ee5430afb12d ID this course is being added to.

The courseId is used to assign the test to a the course it should live on

Request

{
  "courseId": "564a449a2e55ee5430afb12d",
  "data" : {
    "title": "A new test!"
  }
}

Response

{
  "test": {
    "title" : "A new test!",
    //..
  }
}

/v2/tests/:id/user

PUT Add a user to a test

Headers Value Description
x-access-token : string token Token received from authentication.
Params Value Description
id : string 564a449a2e55ee5430afb12d ID for test that you want to update.

Request

{
  "userId" : "564a449a2e5527a8ff12"
} 

Response

{
  "test": {
    "title": "HTML/CSS Test Updated Title",
    //...
  }
}

/v2/tests/:id

PUT Update specific test

Headers Value Description
x-access-token : string token Token received from authentication.
Params Value Description
id : string 564a449a2e55ee5430afb12d ID for test that you want to update.

Request

{
  "title": "HTML/CSS Test Updated Title",
  //...
}

Response

{
  "test": {
    "title": "HTML/CSS Test Updated Title",
    //...
  }
}

/v2/tests/:id/question

PUT Add a new question to a test

Headers Value Description
x-access-token : string token Token received from authentication.
Params Value Description
id : string 58488c6410658216a3d7ff77 ID for test that you want to update.

Request

{
  "questionId": "564a449a2e55ee5430afb12d",
}

Response

{ test:
  { 
    _id: '58488c6410658216a3d7ff77',
    title: 'Test added to a course Updated',
    created_at: 1481149540735,
    created_by: '58458e32044f593aff3071bc',
    __v: 0,
    course: '583d9f009a28f634e40e1d46',
    questions: [{
      title: "Sample Question"
    }] 
  } 
}

/v2/tests/:id/evaluate

POST Mark the provided test

Headers Value Description
x-access-token : string token Token received from authentication.
Params Value Description
id : string 58488c6410658216a3d7ff77 ID for test that you want to evaluate.

Request

{
    userId: "58488cfa2340658213r21ff",
    answer: {
      questionId: "58488cfafasdf78917r21aa",
      answer: "flexbox"
    }
  }

Response

//If code question
{ 
  result: { 
    "correct": {
      "testResults":[
        {
          "assertionResults":[
            {
              "failureMessages":[],
              "title":"should add 1 and 2 and return 3",
              "status":"passed"
            }
          ],
          "endTime":1481824852348,
          "startTime":1481824852281,
          "status":"passed",
          "summary":"",
          "name":"/Users/ryanchristiani/Sites/HackerYou/chalk-api/testCenter/test_1481824851400.js",
          "message":""
        }
      ],
      "success":true,
      "startTime":1481824851817,
      "numTotalTests":1,
      "numTotalTestSuites":1,
      "numRuntimeErrorTestSuites":0,
      "numPendingTests":0,
      "numPassedTests":1,
      "numFailedTests":0
    },
    "actual":"function add(a,b){return a + b;}",
    "type":"Code",
    "id":"5852da53e36b9e276e8ce33c"
  }
}

//If Multiple Choice
{ 
  result: { 
    "correct": true,
    "actual": 2,
    "multiAnswer": 2
    "type":"Multiple Choice",
    "id":"5852da53e36b9e276e8ce33c"
  }
}


/v2/tests/:id/question

DELETE Remove a question from a test

Headers Value Description
x-access-token : string token Token received from authentication.
Params Value Description
id : string 58488c6410658216a3d7ff77 ID for test that you want to remove.

Request

{
  "questionId": "564a449a2e55ee5430afb12d",
}

Response

{ test:
  { 
    _id: '58488c6410658216a3d7ff77',
    title: 'Test added to a course Updated',
    created_at: 1481149540735,
    created_by: '58458e32044f593aff3071bc',
    __v: 0,
    course: '583d9f009a28f634e40e1d46',
    questions: [] 
  } 
}

/v2/tests/:id

DELETE Remove a test by id

Headers Value Description
x-access-token : string token Token received from authentication.
Params Value Description
id : string 58488c6410658216a3d7ff77 ID for test that you want to update.

Response

{ 
  success: true
}