示例#1
0
func TestClientChecks(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test in short mode.")
	}

	is := is.New(t)
	checkToken(is)

	c := New(*token)
	is.NotNil(c)

	nowDate = Date(time.Now().Add(-5 * time.Hour * 24))

	nameNum := rand.Int31()

	a := &Applicant{
		Country:   "USA",
		FirstName: "Tyler" + strconv.Itoa(int(nameNum)),
		LastName:  "Bunnell" + strconv.Itoa(int(nameNum)),
		Email:     "tyler" + strconv.Itoa(int(nameNum)) + "@fake.com",
		Gender:    "male",
		Dob:       &nowDate,
		IDNumbers: testIDNumbers,
		Telephone: "555-738-6874",
		Addresses: testAddress,
	}

	a, err := c.CreateApplicant(a)
	is.NotErr(err)
	is.NotZero(a.ID)
	is.NotZero(a.Href)

	ch, err := c.CreateCheck(a.ID,
		NewCheckRequest(CheckType.Express,
			ReportType.USA.Identity, ReportType.USA.DrivingRecord))
	is.NotErr(err)
	is.NotNil(ch)
	is.NotZero(ch.ID)
	is.NotZero(ch.CreatedAt)
	is.Equal(ch.Type, "express")
	is.Equal(ch.Result, "consider")
	is.NotZero(ch.Href)
	is.NotNil(ch.Reports)
	is.Equal(len(ch.Reports), 2)

	ch, err = c.ReadCheck(a.ID, ch.ID)
	is.NotErr(err)
	is.NotNil(ch)
	is.NotZero(ch.ID)
	is.NotZero(ch.CreatedAt)
	is.Equal(ch.Type, "express")
	is.Equal(ch.Result, "consider")
	is.NotZero(ch.Href)
	is.NotNil(ch.Reports)
	is.Equal(len(ch.Reports), 2)

	chs, err := c.ReadChecks(a.ID)
	is.NotErr(err)
	is.NotEqual(len(chs), 0)
}
示例#2
0
func TestWebhook(t *testing.T) {
	is := is.New(t)

	inString := `{
  "id": "507f1f77bcf86cd799439011",
  "object": "event",
  "type": "report.completed",
  "created_at": "2014-01-18T12:34:00Z",
  "webhook_url": "https://yourcompany.com/checkr/incoming",
  "data": {
    "object": {
      "id": "4722c07dd9a10c3985ae432a",
      "object": "report",
      "uri": "/v1/reports/532e71cfe88a1d4e8d00000d",
      "created_at": "2014-01-18T12:34:00Z",
      "received_at": "2014-01-18T12:34:00Z",
      "status": "clear",
      "package": "driver_pro",
      "candidate_id": "e44aa283528e6fde7d542194",
      "ssn_trace_id": "539fd88c101897f7cd000001",
      "sex_offender_search_id": "539fd88c101897f7cd000008",
      "national_criminal_search_id": "539fd88c101897f7cd000006",
      "county_criminal_search_ids": [
        "539fdcf335644a0ef4000001",
        "532e71cfe88a1d4e8d00000i"
      ],
      "motor_vehicle_report_id": "539fd88c101897f7cd000007"
    }
  }
}`

	r, err := http.NewRequest("POST", "https://webhook.com", strings.NewReader(inString))
	is.NotErr(err)

	mac := hmac.New(sha256.New, []byte(Key))
	mac.Write([]byte(inString))
	sig := hex.EncodeToString(mac.Sum(nil))

	r.Header.Set(webhookSignatureKey, sig)

	w, err := NewWebhook(r)
	is.NotErr(err)
	is.True(w.IsReport())
	is.False((w.IsCandidate()))

	rep := w.Report()
	is.NotNil(rep)
	is.Equal(w.Type, WebhookType.Report.Completed)
	is.NotZero(rep.MotorVehicleReportID)
}
示例#3
0
func TestTimestamp(t *testing.T) {
	is := is.New(t)

	expected, err := time.Parse(timestampFormat, "2014-01-18T12:34:00Z")
	is.NotErr(err)
	in := []byte(`"2014-01-18T12:34:00Z"`)

	var dob Timestamp
	err = json.Unmarshal(in, &dob)
	is.NotErr(err)
	is.True(dob.Equal(expected))

	b, err := json.Marshal(dob)
	is.NotErr(err)
	is.Equal(string(b), `"2014-01-18T12:34:00Z"`)

}
示例#4
0
func TestShortDate(t *testing.T) {
	is := is.New(t)

	expected, err := time.Parse(shortDateFormat, "1970-01-22")
	is.NotErr(err)
	in := []byte(`"1970-01-22"`)

	var dob ShortDate
	err = json.Unmarshal(in, &dob)
	is.NotErr(err)
	is.True(dob.Equal(expected))

	b, err := json.Marshal(dob)
	is.NotErr(err)
	is.Equal(string(b), `"1970-01-22"`)

}
示例#5
0
func TestClientApplicants(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test in short mode.")
	}

	is := is.New(t)
	checkToken(is)

	c := New(*token)
	is.NotNil(c)

	nameNum := rand.Int31()

	nowDate = Date(time.Now().Add(-5 * time.Hour * 24))

	a := &Applicant{
		Country:   "USA",
		FirstName: "Tyler" + strconv.Itoa(int(nameNum)),
		LastName:  "Bunnell" + strconv.Itoa(int(nameNum)),
		Email:     "tyler" + strconv.Itoa(int(nameNum)) + "@fake.com",
		Gender:    "male",
		Dob:       &nowDate,
		IDNumbers: testIDNumbers,
		Telephone: "555-738-6874",
		Addresses: testAddress,
	}

	a, err := c.CreateApplicant(a)
	is.NotErr(err)
	is.NotZero(a.ID)
	is.NotZero(a.Href)

	a, err = c.ReadApplicant(a.ID)
	is.NotErr(err)
	is.NotZero(a.ID)
	is.NotZero(a.Href)

	apps, err := c.ReadApplicants()
	is.NotErr(err)
	is.NotEqual(len(apps), 0)
}
示例#6
0
func TestCheckrCandidates(t *testing.T) {
	is := is.New(t)

	c := createCandidate(is)

	rc, err := Candidates.Retrieve(c.ID)
	is.NotErr(err)

	is.Equal(c.ID, rc.ID)
	is.Equal(c.Object, rc.Object)
	is.Equal(c.URI, rc.URI)
	is.True(c.CreatedAt.Equal(rc.CreatedAt.Time))
}
示例#7
0
func TestEventUnmarshalEvent(t *testing.T) {
	is := is.New(t)

	body := []byte(`{"payload":{"resource_type":"report","action":"completed","object":{"id":"50e65977-496f-464a-be73-836def7bea6c","status":"completed","completed_at":"2006-01-02 15:04:05 MST","href":"https://api.onfido.com/checks/dd29776f-26fa-452f-90f1-9c8ce4fcec3e/reports/50e65977-496f-464a-be73-836def7bea6c"}}}`)

	c := New("none")
	c.WebhookToken = "kCxrT1iqSqlxf1OeQi2On5M-1fA6xnr3"

	r, err := http.NewRequest("POST", "/webhook", bytes.NewReader(body))
	is.NotErr(err)
	r.Header.Set("X-Signature", "8fe7130c7e193b5049daafb507ad246047c69bc4")

	event, err := c.UnmarshalEvent(r)
	is.NotErr(err)
	is.Equal(event.Payload.ResourceType, "report")
	is.Equal(event.Payload.Action, "completed")
	is.NotZero(event.Payload.Object.ID)
	is.Equal(event.Payload.Object.Status, "completed")
	tc, err := time.Parse(eventTimeFormat, "2006-01-02 15:04:05 MST")
	is.NotErr(err)
	is.Equal(event.Payload.Object.CompletedAt, tc)
	is.Equal(event.Payload.Object.Href, "https://api.onfido.com/checks/dd29776f-26fa-452f-90f1-9c8ce4fcec3e/reports/50e65977-496f-464a-be73-836def7bea6c")
}
示例#8
0
文件: pv_test.go 项目: tylerb/pv
func TestPVUnmarshal(t *testing.T) {
	is := is.New(t)
	inJSON := []byte(`{"name":"Tyler Bunnell"}`)

	var out ts

	err := Unmarshal("bogus", inJSON, &out)
	is.Err(err)
	is.Equal(err, ErrInvalidVersion)

	is.NotErr(Unmarshal("20150902", inJSON, &out))
	is.Equal(out.FirstName, "Tyler")
	is.Equal(out.LastName, "Bunnell")
}
示例#9
0
func TestCheckrReports(t *testing.T) {
	is := is.New(t)

	c := createCandidate(is)

	r, err := Reports.Create(c.ID, "driver_pro")
	is.NotErr(err)

	is.NotZero(r.ID)
	is.NotZero(r.Object)
	is.NotZero(r.URI)
	is.NotZero(r.SSNTraceID)
	is.NotZero(r.MotorVehicleReportID)
}