seekia/internal/profiles/calculatedAttributes/calculatedAttributes_test.go

87 lines
2.5 KiB
Go
Raw Normal View History

package calculatedAttributes_test
import "seekia/internal/profiles/calculatedAttributes"
import "seekia/internal/appUsers"
import "seekia/internal/generate"
import "seekia/internal/identity"
import "seekia/internal/localFilesystem"
import "seekia/internal/profiles/readProfiles"
import "testing"
func TestCalculatedAttributes(t *testing.T){
err := localFilesystem.InitializeAppDatastores()
if (err != nil){
t.Fatalf("InitializeAppDatastores failed: " + err.Error())
}
err = appUsers.InitializeAppUserForTests(true, true)
if (err != nil) {
t.Fatalf("InitializeAppUserForTests failed: " + err.Error())
}
calculatedAttributesList := calculatedAttributes.GetCalculatedAttributesList()
for i:=0; i<10; i++{
identityPublicKey, identityPrivateKey, err := identity.GetNewRandomPublicPrivateIdentityKeys()
if (err != nil){
t.Fatalf("GetNewRandomPublicPrivateIdentityKeys failed: " + err.Error())
return
}
fakeProfileBytes, err := generate.GetFakeProfile("Mate", identityPublicKey, identityPrivateKey, 1)
if (err != nil){
t.Fatalf("GetFakeProfile failed: " + err.Error())
return
}
ableToRead, profileVersion, _, profileAuthor, _, _, rawProfileMap, err := readProfiles.ReadProfile(true, fakeProfileBytes)
if (err != nil){
t.Fatalf("ReadProfile failed: " + err.Error())
return
}
if (ableToRead == false){
t.Fatalf("ReadProfile cant read profile returned from GetFakeProfile.")
return
}
profileType, err := identity.GetIdentityTypeFromIdentityHash(profileAuthor)
if (err != nil){
t.Fatalf("ReadProfile returning invalid identityHash: " + err.Error())
return
}
getProfileAttributesFunction := func(attributeName string)(bool, int, string, error){
attributeExists, attributeValue, err := readProfiles.GetFormattedProfileAttributeFromRawProfileMap(rawProfileMap, attributeName)
if (err != nil) { return false, 0, "", err }
if (attributeExists == false){
return false, profileVersion, "", nil
}
return true, profileVersion, attributeValue, nil
}
for _, attributeName := range calculatedAttributesList{
if (profileType != "Moderator"){
if (attributeName == "IdentityScore" || attributeName == "Controversy" || attributeName == "NumberOfReviews"){
continue
}
}
_, _, _, err := calculatedAttributes.GetAnyProfileAttributeIncludingCalculated(attributeName, getProfileAttributesFunction)
if (err != nil) {
t.Fatalf("GetAnyProfileAttributeIncludingCalculated failed: " + err.Error())
return
}
}
}
}