<commit_before>package checkToken

import (
	"github.com/AitorGuerrero/UserGo/user"
	userImplementation "github.com/AitorGuerrero/UserGo/implementation/user"

	t "testing"
)

var id = "dabfe523-fae0-4a1c-8923-5e51ffeb3e91"
var userSource userImplementation.Source
var userFactory user.Factory
var com Command
var req Request
var parsedId user.Id
var passkeyEncryptor = user.PasskeyEncryptor{userImplementation.Encryptor{}}
var tokenChecker = user.TokenChecker{}

func beforeEach() {
	parsedId, _ = user.ParseId(id)
	userSource = userImplementation.Source{map[string]*user.User{}}
	userFactory = user.Factory{passkeyEncryptor}
	com = Command{tokenChecker, &userSource}
	req = Request{}
}

func TestIfTheUserDoesNotExistsShouldReturnAnError (t *t.T) {
	beforeEach()
	req.Token = "<PASSWORD>"
	err := com.Execute(req)
	if _, ok := err.(InvalidIdError); !ok {
		t.Error(err)
	}
}

func TestIfTheTokenIsInvalidShouldReturnAnError (t *t.T) {
	beforeEach()
	createUser()
	req.Token = "<PASSWORD>"
	req.UserId = id
	err := com.Execute(req)
	if _, ok := err.(IncorrectTokenError); !ok {
		t.Error(err)
	}
}

func TestIfTheUserHasNotAccessToNamespaceHouldReturnError (t *t.T) {
	beforeEach()
	u := createUser()
	req.Token = string(u.Token().Code)
	req.UserId = id
	err := com.Execute(req)
	if _, ok := err.(AccessErrorToNamespace); !ok {
		t.Error(err)
	}
}

func createUser() (u user.User) {
	u = userFactory.Make(parsedId, "passkey")
	u.GenerateToken()
	userSource.Add(&u)

	return
}
<commit_msg>Token check command, ok test<commit_after>package checkToken

import (
	"github.com/AitorGuerrero/UserGo/user"
	userImplementation "github.com/AitorGuerrero/UserGo/implementation/user"

	t "testing"
)

var id = "dab<PASSWORD>-fae0-4a1c-8923-<PASSWORD>1"
var testNameSpace = "/test/namespace"
var userSource userImplementation.Source
var userFactory user.Factory
var com Command
var req Request
var parsedId user.Id
var passkeyEncryptor = user.PasskeyEncryptor{userImplementation.Encryptor{}}
var tokenChecker = user.TokenChecker{}

func beforeEach() {
	parsedId, _ = user.ParseId(id)
	userSource = userImplementation.Source{map[string]*user.User{}}
	userFactory = user.Factory{passkeyEncryptor}
	com = Command{tokenChecker, &userSource}
	req = Request{}
}

func TestIfTheUserDoesNotExistsShouldReturnAnError (t *t.T) {
	beforeEach()
	req.Token = "PisToken"
	err := com.Execute(req)
	if _, ok := err.(InvalidIdError); !ok {
		t.Error(err)
	}
}

func TestIfTheTokenIsInvalidShouldReturnAnError (t *t.T) {
	beforeEach()
	createUser()
	req.Token = "<PASSWORD>"
	req.UserId = id
	err := com.Execute(req)
	if _, ok := err.(IncorrectTokenError); !ok {
		t.Error(err)
	}
}

func TestIfTheUserHasNotAccessToNamespaceShouldReturnError (t *t.T) {
	beforeEach()
	u := createUser()
	req.Token = string(u.Token().Code)
	req.UserId = id
	req.Namespace = "/fake/Namespace"
	err := com.Execute(req)
	if _, ok := err.(AccessErrorToNamespace); !ok {
		t.Error(err)
	}
}

func TestIfTokenIsCorrectShouldNotResturnError(t *t.T) {
	beforeEach()
	u := createUser()
	req.Token = string(u.Token().Code)
	req.UserId = id
	req.Namespace = testNameSpace
	err := com.Execute(req)
	if nil != err {
		t.Error(err)
	}
}

func createUser() (u user.User) {
	u = userFactory.Make(parsedId, "<PASSWORD>")
	u.GenerateToken()
	u.GrantAccessTo(user.Namespace(testNameSpace))
	userSource.Add(&u)

	return
}

{'fraction_non_alphanumeric': 0.13710879284649777, 'fraction_numerical': 0.007153502235469449, 'mean_word_length': 5.135283363802559, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5822526', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1246, 'n_words': 236}