Exemplo n.º 1
0
func TestSegmentPager(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	var (
		completed     bool
		countEntities int
	)

	client := NewLytics(mock.MockApiKey, nil, nil)

	// start the paging routine
	scan := client.PageSegmentId(mock.MockSegmentID1)
	assert.Equal(t, nil, scan.Err())

	// handle processing the entities
	for {
		e := scan.Next()
		if e == nil {
			completed = true
			break
		}
		countEntities++
		assert.Equal(t, e["email"], fmt.Sprintf("*****@*****.**", countEntities))
	}
	assert.Equal(t, countEntities, 13)
	assert.Equal(t, completed, true)
	t.Logf("*** COMPLETED SCAN: %d total entities", scan.Total)
}
Exemplo n.º 2
0
func TestGetSegmentSizes(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	var segments []string

	client := NewLytics(mock.MockApiKey, nil, nil)

	segments = []string{
		mock.MockSegmentID1,
	}

	seg, err := client.GetSegmentSizes(segments)
	assert.Equal(t, err, nil)
	assert.T(t, seg[0].Id == segments[0])

	segments = []string{
		mock.MockSegmentID1,
		mock.MockSegmentID2,
	}

	// params
	seg, err = client.GetSegmentSizes(segments)
	assert.Equal(t, err, nil)
	assert.T(t, len(seg) == 2)
}
Exemplo n.º 3
0
func TestGetSegment(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	client := NewLytics(mock.MockApiKey, nil, nil)
	seg, err := client.GetSegment(mock.MockSegmentID1)
	assert.Equal(t, err, nil)
	assert.T(t, seg.Id == mock.MockSegmentID1)
}
Exemplo n.º 4
0
func TestGetSegmentCollection(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	client := NewLytics(mock.MockApiKey, nil, nil)
	collection, err := client.GetSegmentCollection(mock.MockSegmentCollection)

	assert.Equal(t, err, nil)
	assert.Equal(t, collection.Slug, "goal_funnel")
	assert.T(t, len(collection.Collection) == 2)
	assert.Equal(t, collection.Collection[0].Id, mock.MockSegmentID1)
	assert.Equal(t, collection.Collection[1].Id, mock.MockSegmentID2)
}
Exemplo n.º 5
0
func TestValidateSegment(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	client := NewLytics(mock.MockApiKey, nil, nil)

	valid, err := client.ValidateSegment("FILTER AND (created >= \"now-30d\", aspects = \"articles\") FROM content")
	assert.Equal(t, err, nil)
	assert.T(t, valid)

	valid, err = client.ValidateSegment("")
	assert.NotEqual(t, err, nil)
	assert.T(t, !valid)
}
Exemplo n.º 6
0
func TestGetSegmentCollectionList(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	client := NewLytics(mock.MockApiKey, nil, nil)
	collections, err := client.GetSegmentCollectionList()

	assert.Equal(t, err, nil)
	assert.T(t, len(collections) == 2)
	assert.Equal(t, collections[0].Slug, "goal_funnel")
	assert.T(t, len(collections[0].Collection) == 2)
	assert.Equal(t, collections[1].Slug, "mobile")
	assert.T(t, len(collections[1].Collection) == 3)
}
Exemplo n.º 7
0
func TestGetSegmentAttribution(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	segments := []string{
		mock.MockSegmentID1,
		mock.MockSegmentID2,
	}

	client := NewLytics(mock.MockApiKey, nil, nil)
	attr, err := client.GetSegmentAttribution(segments)

	assert.Equal(t, err, nil)
	assert.T(t, len(attr[0].Metrics) == 5)
	assert.T(t, len(attr[1].Metrics) == 5)
}
Exemplo n.º 8
0
func TestCreateSegment(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	client := NewLytics(mock.MockApiKey, nil, nil)

	ql := "FILTER AND (created >= \"now-30d\", aspects = \"articles\") FROM content"

	seg, err := client.CreateSegment("Recent Articles", ql, "recent_articles")
	assert.Equal(t, err, nil)
	assert.T(t, seg.Id != "")
	assert.Equal(t, seg.FilterQL, ql)

	seg, err = client.CreateSegment("Invalid Segment", "", "invalid")
	assert.NotEqual(t, err, nil)
}
Exemplo n.º 9
0
func TestGetSegments(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	// user segment
	client := NewLytics(mock.MockApiKey, nil, nil)
	segs, err := client.GetSegments("user")
	assert.Equal(t, err, nil)
	assert.T(t, len(segs) > 1)
	assert.Equal(t, segs[0].Table, "user")

	// content segment
	segs, err = client.GetSegments("content")
	assert.Equal(t, err, nil)
	assert.T(t, len(segs) > 1)
	assert.Equal(t, segs[0].Table, "content")
}