about summary refs log tree commit diff
path: root/src/rest-api/handler/handler_test.go
blob: 183d584d4b9ec7e9d68ee766a12d7e1647644e90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package handler

import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/Baitinq/fs-tracer-backend/lib"
	"github.com/stretchr/testify/require"
	gomock "go.uber.org/mock/gomock"
)

func TestHandleGet(t *testing.T) {
	ctrl := gomock.NewController(t)
	db := NewMockDB(ctrl)
	recorder := httptest.NewRecorder()

	handler := Handler{db: db}

	file := &lib.File{
		User_id:       "USER_ID",
		Absolute_path: "/tmp/file.txt",
	}
	db.EXPECT().GetLatestFileByPath(gomock.Any(), "/tmp/file.txt", "USER_ID").Return(file, nil)

	handler.handleGet(recorder, httptest.NewRequest(http.MethodGet, "/file/?path=%2ftmp%2Ffile.txt", nil), "USER_ID")

	require.Equal(t, http.StatusOK, recorder.Code)
	require.Equal(t, fmt.Sprintln("File: ", file), recorder.Body.String())
}