Пример #1
0
func GetFakeInfinityOwnAddressHandler() *OwnAddressHandler {
	conf := configuration.ReadConfigInRecursive()
	ext := infinity.GetInfinityAddressSupplier(conf.Taxis["fake"].Api, "fake")
	own_ah := NewOwnAddressHandler(conf.Main.ElasticConn, conf.Taxis["fake"].Api.GeoOrbit, ext)
	return own_ah
}
func TestMessageProcessor(t *testing.T) {
	conf := configuration.ReadConfigInRecursive()
	conf.Main.Database.Name = conf.Main.Database.Name + "_autotest"
	qs := NewQuestStorage(conf.Main.Database.ConnString, conf.Main.Database.Name)
	cs := configuration.NewCommandsStorage(conf.Main.Database.ConnString, conf.Main.Database.Name)
	qp := QuestMessageProcessor{Storage: qs, ConfigStorage: cs}
	prep_keys(qs)
	k, d := kd(0, 0)
	out := qp.ProcessMessage(prep_pack("U1", k))
	if !strings.Contains(out.Body, d) {
		t.Error("First key not found %v", out.Body)
	}
	k, d = kd(1, 0)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Next key not found %v", out.Body)
	}

	k, d = kd(0, 0)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Next key not found %v", out.Body)
	}
	k, d = kd(1, 0)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Next key not found %v", out.Body)
	}
	k, d = kd(1, 0)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Next key not found %v", out.Body)
	}

	k, d = kd(0, 1)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Go to another command err %v", out.Body)
	}

	k, d = kd(2, 0)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if strings.Contains(out.Body, d) {
		t.Error("From ahother command you can not send keys 2 %v", out.Body)
	}

	k, d = kd(1, 0)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if strings.Contains(out.Body, d) {
		t.Error("From ahother command you can not send keys 1 %v", out.Body)
	}

	k, d = kd(0, 0)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Go to first command err %v", out.Body)
	}

	k, d = kd(1, 1)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if strings.Contains(out.Body, d) {
		t.Error("Can not send code of another team %v", out.Body)
	}

	k, d = kd(1, 2)
	out = qp.ProcessMessage(prep_pack("U1", k))
	if strings.Contains(out.Body, d) {
		t.Error("Can not send code of another team %v", out.Body)
	}

	k, d = kd(1, 2)
	out = qp.ProcessMessage(prep_pack("U2", k))
	if strings.Contains(out.Body, d) {
		t.Error("you must register at first 2 %v", out.Body)
	}
	k, d = kd(1, 1)
	out = qp.ProcessMessage(prep_pack("U2", k))
	if strings.Contains(out.Body, d) {
		t.Error("you must register at first 1 %v", out.Body)
	}
	k, d = kd(1, 0)
	out = qp.ProcessMessage(prep_pack("U2", k))
	if strings.Contains(out.Body, d) {
		t.Error("you must register at first 0 %v", out.Body)
	}

	k, d = kd(0, 0)
	out = qp.ProcessMessage(prep_pack("U2", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Next user not adding to team 0 %v", out.Body)
	}

	k, d = kd(1, 0)
	out = qp.ProcessMessage(prep_pack("U2", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Next user can not send next key to team 0 %v", out.Body)
	}

	k, d = kd(0, 1)
	out = qp.ProcessMessage(prep_pack("U2", k))
	if !strings.Contains(out.Body, d) {
		t.Error("Next user go to another team to team 1 %v", out.Body)
	}

}