package service

import (
	"testing"
	"time"

	"app.yhyue.com/moapp/jybase/mongodb"
)

var MgoT *mongodb.MongodbSim

func init() {
	MgoT = &mongodb.MongodbSim{
		MongodbAddr: "192.168.3.206:27080",
		Size:        10,
		DbName:      "qfw",
		ReplSet:     "",
	}
	MgoT.InitPool()
}
func TestSubseribeService_Update(t *testing.T) {
	type fields struct {
		Mgo          *mongodb.MongodbSim
		UserId       string
		Types        string
		Area         map[string]interface{}
		Buyerclass   []string
		Items        []map[string]interface{}
		Infotype     []string
		Matchway     string
		Projectmatch string
		Ratemode     string
		Apppush      string
		Mailpush     string
		Mail         string
	}
	tests := []struct {
		name    string
		fields  fields
		want    int64
		wantErr bool
	}{
		// TODO: Add test cases.
		{
			name: "无user测试",
			fields: fields{
				Mgo:    MgoT,
				UserId: "",
			},
		},
		{
			fields: fields{
				Mgo:    MgoT,
				UserId: "6103bb722abfa5f4d81bb1d2",
				Area:   map[string]interface{}{},
			},
		},
		{
			fields: fields{
				Mgo:    MgoT,
				UserId: "6103bb722abfa5f4d81bb1d1",
				Area: map[string]interface{}{
					"北京": []string{},
				},
				Items: []map[string]interface{}{
					map[string]interface{}{
						"s_item":     "zxl的分类名称1",
						"updatetime": time.Now().Unix(),
						"a_key": []map[string]interface{}{
							map[string]interface{}{
								"key":        []string{"你好2"},
								"notkey":     []string{},
								"appendkey":  []string{},
								"updatetime": time.Now().Unix(),
							},
							map[string]interface{}{
								"key":        []string{"你好1"},
								"notkey":     []string{},
								"appendkey":  []string{},
								"updatetime": time.Now().Unix(),
							},
						},
					},
				},
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			this := &SubseribeService{
				Mgo:          *MgoT,
				UserId:       tt.fields.UserId,
				Types:        tt.fields.Types,
				Area:         tt.fields.Area,
				Buyerclass:   tt.fields.Buyerclass,
				Items:        tt.fields.Items,
				Infotype:     tt.fields.Infotype,
				Matchway:     tt.fields.Matchway,
				Projectmatch: tt.fields.Projectmatch,
				Ratemode:     tt.fields.Ratemode,
				Apppush:      tt.fields.Apppush,
				Mailpush:     tt.fields.Mailpush,
				Mail:         tt.fields.Mail,
			}
			got, err := this.Update()
			if (err != nil) != tt.wantErr {
				t.Errorf("Update() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if got != tt.want {
				t.Errorf("Update() got = %v, want %v", got, tt.want)
			}
		})
	}
}
