package session

import "testing"

var sessions = ListSession{
	Data: []ItemSession{
		{
			PublicSessionID: "06674bdf-13f1-4f78-a40a-242fd76e4cd1",
			IP:              "10.244.0.243",
			User:            "someuser",
		},
		{
			PublicSessionID: "06674bdf-13f1-4f78-a40a-242fd76e4cd5",
			IP:              "10.244.0.242",
			User:            "someuser2",
		},
		{
			PublicSessionID: "06674bdf-13f1-4f78-a40a-242fd76e4cd7",
			IP:              "10.244.0.243",
			User:            "someuser2",
		},
	},
	EntryCount: 3,
}

func TestFilterByID(t *testing.T) {
	actual := sessions.FilterByID("06674bdf-13f1-4f78-a40a-242fd76e4cd1").FindOne()

	if actual.PublicSessionID != "06674bdf-13f1-4f78-a40a-242fd76e4cd1" {
		t.Fatal("expected ID 1, found: ", actual.PublicSessionID)
	}
}

func TestFilterByUser(t *testing.T) {
	actual := sessions.FilterByUser("someuser").FindOne()

	if actual.User != "someuser" {
		t.Fatal("expected User 'someuser', found: ", actual.User)
	}
}

func TestFilterByIP(t *testing.T) {
	actual := sessions.FilterByIP("10.244.0.243")

	if len(actual.Data) != 2 {
		t.Fatal("expected 2 found, actual: ", len(actual.Data))
	}

	for _, item := range actual.Data {
		if item.IP != "10.244.0.243" {
			t.Fatal("expected IP '10.244.0.243', found: ", item.IP)
		}
	}
}
