Example #1
0
func BuildSampleDraft() *resource.Draft {
	draft := resource.NewDraft()
	draft.Body = types.String("nice body")
	draft.Direction = types.String("out")
	draft.Status = types.String("draft")
	return draft
}
Example #2
0
func BuildSampleAttachment() *resource.Attachment {
	attach := resource.NewAttachment()
	attach.FileName = types.String("test.png")
	attach.ContentType = types.String("image/png")
	attach.SetContent("test.png")
	return attach
}
func TestNoteIntegration(t *testing.T) {

	if testing.Short() {
		t.Skip("integration tests are skipped in short mode.")
	}
	client := CreateClient()

	createCaseWithNote := func() (*resource.Case, *resource.Note) {
		cse := BuildSampleCase()
		createdCase, _, err := client.Case.Create(cse)
		So(err, ShouldBeNil)
		note := BuildSampleNote()
		createdNote, _, err := client.Case.Note.Create(createdCase.GetResourceId(), note)
		log.Printf("note response %v", createdNote)
		So(err, ShouldBeNil)
		return createdCase, createdNote
	}

	Convey("should be able to create a case note", t, func() {
		createCaseWithNote()
	})

	Convey("should be able to show a case note", t, func() {
		cse, note := createCaseWithNote()
		showNote, _, err := client.Case.Note.Get(cse.GetResourceId(), note.GetResourceId())
		So(err, ShouldBeNil)
		So(showNote, ShouldNotBeNil)
		So(showNote.GetResourceId(), ShouldEqual, note.GetResourceId())
		So(*showNote.Body, ShouldEqual, *note.Body)
	})

	Convey("should be able to update a case note", t, func() {
		cse, note := createCaseWithNote()
		body := fmt.Sprintf("body updated at %v", time.Now())
		note.Body = types.String(body)
		updatedNote, _, err := client.Case.Note.Update(cse.GetResourceId(), note)
		So(err, ShouldBeNil)
		So(updatedNote, ShouldNotBeNil)
		So(*updatedNote.Body, ShouldEqual, body)
	})

	Convey("should be able to delete a case note", t, func() {
		cse, note := createCaseWithNote()
		_, err := client.Case.Note.Delete(cse.GetResourceId(), note.GetResourceId())
		So(err, ShouldBeNil)
	})

	Convey("should be able to list case notes", t, func() {
		cse, _ := createCaseWithNote()
		params := url.Values{}
		params.Add("sort_field", "created_at")
		params.Add("sort_direction", "asc")
		collection, _, err := client.Case.Note.List(cse.GetResourceId(), &params)
		So(err, ShouldBeNil)
		So(collection, ShouldNotBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

}
func TestReplyIntegration(t *testing.T) {
	if testing.Short() {
		t.Skip("integration tests are skipped in short mode.")
	}
	client := CreateClient()

	Convey("should be able to retrieve a list of case replies", t, func() {
		listParams := url.Values{}
		listParams.Add("sort_field", "created_at")
		listParams.Add("sort_direction", "asc")
		collection, _, err := client.Case.Reply.List("1", &listParams)
		So(err, ShouldBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

	Convey("should be able create a case reply", t, func() {
		cse := BuildSampleCase()
		createdCase, _, err := client.Case.Create(cse)
		So(err, ShouldBeNil)
		reply := BuildSampleReply()
		createdReply, _, err := client.Case.Reply.Create(createdCase.GetResourceId(), reply)
		So(err, ShouldBeNil)
		So(createdReply, ShouldNotBeNil)
		So(*createdReply.Body, ShouldEqual, "some body")
	})

	Convey("should be able to update a case reply", t, func() {
		body := types.String(fmt.Sprintf("updated body at %v", time.Now()))
		cse := BuildSampleCase()
		createdCase, _, err := client.Case.Create(cse)
		So(err, ShouldBeNil)
		reply := BuildSampleReply()
		createdReply, _, err := client.Case.Reply.Create(createdCase.GetResourceId(), reply)
		So(err, ShouldBeNil)
		createdReply.Body = body
		updatedReply, _, err := client.Case.Reply.Update(createdCase.GetResourceId(), createdReply)
		So(err, ShouldBeNil)
		So(updatedReply, ShouldNotBeNil)
		So(*createdReply.Body, ShouldEqual, *body)
	})

	Convey("should be able to delete a case reply", t, func() {
		cse := BuildSampleCase()
		createdCase, _, err := client.Case.Create(cse)
		So(err, ShouldBeNil)
		reply := BuildSampleReply()
		createdReply, _, err := client.Case.Reply.Create(createdCase.GetResourceId(), reply)
		So(err, ShouldBeNil)
		_, err = client.Case.Reply.Delete(createdCase.GetResourceId(), createdReply.GetResourceId())
		So(err, ShouldBeNil)
	})

}
Example #5
0
func BuildSampleCompany() *resource.Company {
	companyId, err := strconv.Atoi(os.Getenv("COMPANY_ID"))
	if err == nil {
		companyId = DefaultCompanyId
	}
	companyName := types.String(fmt.Sprintf("Acme Corp %v", time.Now()))
	company := resource.CompanyBuilder.
		SetString("Name", *companyName).
		AddDomain("amce.org").
		AddHrefLink("customer", fmt.Sprintf("/api/v2/companies/%d", companyId)).
		BuildCompany()
	return &company
}
func TestCustomerIntegration(t *testing.T) {
	if testing.Short() {
		t.Skip("integration tests are skipped in short mode.")
	}
	client := CreateClient()

	Convey("should be able to retrieve a customer by ID", t, func() {
		customer, _, err := client.Customer.Get(fmt.Sprintf("%d", DefaultCustomerId))
		So(err, ShouldBeNil)
		So(customer, ShouldNotBeNil)
	})

	Convey("should be able to retrieve a list of customers", t, func() {
		listParams := url.Values{}
		listParams.Add("sort_field", "created_at")
		listParams.Add("sort_direction", "asc")
		collection, _, err := client.Customer.List(&listParams)
		So(err, ShouldBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

	Convey("should be able to search for customers", t, func() {
		searchParams := url.Values{}
		searchParams.Add("sort_field", "created_at")
		searchParams.Add("sort_direction", "asc")
		searchParams.Add("max_id", "200000000")
		collection, _, err := client.Customer.Search(&searchParams, nil)
		So(err, ShouldBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

	Convey("should be able to create a customer", t, func() {
		customer := resource.NewCustomer()
		customer.FirstName = types.String("James")
		customer.LastName = types.String("Dean")
		newCustomer, _, err := client.Customer.Create(customer)
		So(err, ShouldBeNil)
		So(newCustomer, ShouldNotBeNil)
	})

	Convey("should be able to update a customer", t, func() {
		background := fmt.Sprintf("background updated at %v", time.Now())
		customer := resource.NewCustomer()
		customer.Id = types.Integer(DefaultCustomerId)
		customer.Background = types.String(background)
		updatedCustomer, _, err := client.Customer.Update(customer)
		So(err, ShouldBeNil)
		So(updatedCustomer, ShouldNotBeNil)
		So(*updatedCustomer.Background, ShouldEqual, background)
	})

	Convey("should be able to retrieve cases for a customer", t, func() {
		params := url.Values{}
		params.Add("sort_field", "created_at")
		params.Add("sort_direction", "asc")
		collection, _, err := client.Customer.Cases(fmt.Sprintf("%d", DefaultCustomerId), &params)
		So(err, ShouldBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

}
func TestCaseIntegration(t *testing.T) {
	if testing.Short() {
		t.Skip("integration tests are skipped in short mode.")
	}
	client := CreateClient()
	Convey("should be able to retrieve a case by ID", t, func() {
		cse, _, err := client.Case.Get("1")
		So(err, ShouldBeNil)
		log.Println("case %v", cse)
		So(*cse.Subject, ShouldNotBeBlank)
	})
	Convey("should be able to list cases", t, func() {
		listParams := url.Values{}
		listParams.Add("sort_field", "created_at")
		listParams.Add("sort_direction", "asc")
		collection, _, err := client.Case.List(&listParams)
		So(err, ShouldBeNil)
		log.Println("collection %v", collection)
		So(collection, ShouldHaveSameTypeAs, &resource.Page{})
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})
	Convey("should be able to search for cases", t, func() {
		searchParams := url.Values{}
		searchParams.Add("sort_field", "created_at")
		searchParams.Add("sort_direction", "asc")
		searchParams.Add("status", "new")
		collection, _, err := client.Case.Search(&searchParams, nil)
		So(err, ShouldBeNil)
		log.Println("collection %v", collection)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})
	Convey("should be able to update a case", t, func() {
		subject := types.String(fmt.Sprintf("updated case at %v", time.Now()))
		cse := resource.NewCase()
		cse.Subject = subject
		cse.SetResourceId("1")
		updatedCase, _, err := client.Case.Update(cse)
		So(err, ShouldBeNil)
		log.Printf("Updated case: %v\n", updatedCase)
		So(*updatedCase.Subject, ShouldEqual, *subject)
		So(*updatedCase.Blurb, ShouldNotBeBlank)
	})
	Convey("should be able to create a case", t, func() {
		cse := BuildSampleCase()
		newCase, _, err := client.Case.Create(cse)
		So(err, ShouldBeNil)
		log.Printf("Created case: %v\n", newCase)
		So(newCase.GetResourceId(), ShouldNotBeBlank)
	})
	Convey("should be able to delete a case", t, func() {
		cse := BuildSampleCase()
		newCase, _, err := client.Case.Create(cse)
		So(err, ShouldBeNil)
		resp, err := client.Case.Delete(newCase.GetResourceId())
		log.Printf("Delete response: %v\n", resp)
		So(err, ShouldBeNil)
	})
	Convey("should be able to forward a case", t, func() {
		resp, err := client.Case.Forward("1", "*****@*****.**", "some note")
		So(err, ShouldBeNil)
		log.Printf("Forward response: %v\n", resp)
	})
	Convey("should be able to get case feed", t, func() {
		collection, _, err := client.Case.Feed("1", nil)
		So(err, ShouldBeNil)
		So(collection, ShouldNotBeNil)
		log.Println("collection %v", collection)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})
	Convey("should be able to get case history", t, func() {
		collection, _, err := client.Case.History("1", nil)
		So(err, ShouldBeNil)
		So(collection, ShouldNotBeNil)
		log.Println("collection %v", collection)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})
	Convey("should be able to get case labels", t, func() {
		collection, _, err := client.Case.Labels("1", nil)
		So(err, ShouldBeNil)
		So(collection, ShouldNotBeNil)
		log.Println("collection %v", collection)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})
}
func TestCompanyIntegration(t *testing.T) {
	if testing.Short() {
		t.Skip("integration tests are skipped in short mode.")
	}
	client := CreateClient()

	Convey("should be able to retrieve a company by ID", t, func() {
		company, _, err := client.Company.Get(fmt.Sprintf("%d", DefaultCompanyId))
		So(err, ShouldBeNil)
		So(company, ShouldNotBeNil)
	})

	Convey("should be able to retrieve a list of companies", t, func() {
		listParams := url.Values{}
		listParams.Add("sort_field", "created_at")
		listParams.Add("sort_direction", "asc")
		collection, _, err := client.Company.List(&listParams)
		So(err, ShouldBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

	Convey("should be able to search for companies", t, func() {
		searchParams := url.Values{}
		searchParams.Add("q", "desk.com")
		searchParams.Add("sort_field", "created_at")
		searchParams.Add("sort_direction", "asc")
		collection, _, err := client.Company.Search(&searchParams, nil)
		So(err, ShouldBeNil)
		log.Println("collection %v", collection)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

	Convey("should be able to update a company", t, func() {
		subject := types.String(fmt.Sprintf("desk.com updated company at %v", time.Now()))
		company := resource.NewCompany()
		company.Name = subject
		company.SetResourceId(fmt.Sprintf("%d", DefaultCompanyId))
		updatedCompany, _, err := client.Company.Update(company)
		So(err, ShouldBeNil)
		log.Printf("Updated company: %v\n", updatedCompany)
		So(*updatedCompany.Name, ShouldEqual, *subject)
		So(updatedCompany.Domains[0], ShouldNotBeBlank)
	})

	Convey("should be able to create a company", t, func() {
		company := BuildSampleCompany()
		newCompany, _, err := client.Company.Create(company)
		So(err, ShouldBeNil)
		log.Printf("Created company: %v\n", newCompany)
		So(newCompany.GetResourceId(), ShouldNotBeBlank)
	})

	Convey("should be able to get company cases", t, func() {
		params := url.Values{}
		params.Add("sort_field", "created_at")
		params.Add("sort_direction", "asc")
		collection, _, err := client.Company.Cases(fmt.Sprintf("%d", DefaultCompanyId), &params)
		So(err, ShouldBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})

	Convey("should be able to get company customers", t, func() {
		params := url.Values{}
		params.Add("sort_field", "created_at")
		params.Add("sort_direction", "asc")
		collection, _, err := client.Company.Customers(fmt.Sprintf("%d", DefaultCompanyId), &params)
		So(err, ShouldBeNil)
		So(*collection.TotalEntries, ShouldBeGreaterThan, 0)
		So(*collection.Embedded, ShouldNotBeNil)
	})
}