database_test.go 670 Bytes
Newer Older
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
package tests

import (
	"dfss/dfssp/entities"
	"dfss/mgdb"
	"gopkg.in/mgo.v2/bson"
)

var dbURI string
var dbManager *mgdb.MongoManager

func eraseDatabase() {
	_ = dbManager.Database.DropDatabase()
}

func getRegistrationToken(mail string) string {
	var user entities.User
	_ = dbManager.Get("users").Collection.Find(bson.M{
		"email": mail,
	}).One(&user)

	if len(user.RegToken) == 0 {
		return "badToken"
	}
	return user.RegToken
}
27 28 29 30 31 32 33 34

func getContract(file string, skip int) *entities.Contract {
	var contract entities.Contract
	_ = dbManager.Get("contracts").Collection.Find(bson.M{
		"file.name": file,
	}).Sort("_id").Skip(skip).One(&contract)
	return &contract
}