+
+func TestHandleDelNewsItem(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ {
+ name: "when user does not have permission to delete a news category",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: accessBitmap{},
+ },
+ ID: [2]byte{0, 1},
+ Server: &Server{
+ ThreadedNewsMgr: func() *mockThreadNewsMgr {
+ m := mockThreadNewsMgr{}
+ m.On("NewsItem", []string{"test"}).Return(NewsCategoryListData15{
+ Type: NewsCategory,
+ })
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranDelNewsItem, [2]byte{},
+ NewField(FieldNewsPath,
+ []byte{
+ 0, 1,
+ 0, 0,
+ 4,
+ 0x74, 0x65, 0x73, 0x74,
+ },
+ ),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to delete news categories.")),
+ },
+ },
+ },
+ },
+ {
+ name: "when user does not have permission to delete a news folder",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: accessBitmap{},
+ },
+ ID: [2]byte{0, 1},
+ Server: &Server{
+ ThreadedNewsMgr: func() *mockThreadNewsMgr {
+ m := mockThreadNewsMgr{}
+ m.On("NewsItem", []string{"test"}).Return(NewsCategoryListData15{
+ Type: NewsBundle,
+ })
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranDelNewsItem, [2]byte{},
+ NewField(FieldNewsPath,
+ []byte{
+ 0, 1,
+ 0, 0,
+ 4,
+ 0x74, 0x65, 0x73, 0x74,
+ },
+ ),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to delete news folders.")),
+ },
+ },
+ },
+ },
+ {
+ name: "when user deletes a news folder",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessNewsDeleteFldr)
+ return bits
+ }(),
+ },
+ ID: [2]byte{0, 1},
+ Server: &Server{
+ ThreadedNewsMgr: func() *mockThreadNewsMgr {
+ m := mockThreadNewsMgr{}
+ m.On("NewsItem", []string{"test"}).Return(NewsCategoryListData15{Type: NewsBundle})
+ m.On("DeleteNewsItem", []string{"test"}).Return(nil)
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranDelNewsItem, [2]byte{},
+ NewField(FieldNewsPath,
+ []byte{
+ 0, 1,
+ 0, 0,
+ 4,
+ 0x74, 0x65, 0x73, 0x74,
+ },
+ ),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,
+ Fields: []Field{},
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotRes := HandleDelNewsItem(tt.args.cc, &tt.args.t)
+
+ tranAssertEqual(t, tt.wantRes, gotRes)
+ })
+ }
+}
+
+func TestHandleTranOldPostNews(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ {
+ name: "when user does not have required permission",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: accessBitmap{},
+ },
+ },
+ t: NewTransaction(
+ TranOldPostNews, [2]byte{0, 1},
+ NewField(FieldData, []byte("hai")),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ IsReply: 0x01,
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to post news.")),
+ },
+ },
+ },
+ },
+ {
+ name: "when user posts news update",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessNewsPostArt)
+ return bits
+ }(),
+ },
+ Server: &Server{
+ Config: Config{
+ NewsDateFormat: "",
+ },
+ ClientMgr: func() *MockClientMgr {
+ m := MockClientMgr{}
+ m.On("List").Return([]*ClientConn{})
+ return &m
+ }(),
+ MessageBoard: func() *mockReadWriteSeeker {
+ m := mockReadWriteSeeker{}
+ m.On("Seek", int64(0), 0).Return(int64(0), nil)
+ m.On("Read", mock.AnythingOfType("[]uint8")).Run(func(args mock.Arguments) {
+ arg := args.Get(0).([]uint8)
+ copy(arg, "TEST")
+ }).Return(4, io.EOF)
+ m.On("Write", mock.AnythingOfType("[]uint8")).Return(3, nil)
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranOldPostNews, [2]byte{0, 1},
+ NewField(FieldData, []byte("hai")),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ IsReply: 0x01,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotRes := HandleTranOldPostNews(tt.args.cc, &tt.args.t)
+
+ tranAssertEqual(t, tt.wantRes, gotRes)
+ })
+ }
+}
+
+func TestHandleInviteNewChat(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ {
+ name: "when user does not have required permission",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ return bits
+ }(),
+ },
+ },
+ t: NewTransaction(TranInviteNewChat, [2]byte{0, 1}),
+ },
+ wantRes: []Transaction{
+ {
+ IsReply: 0x01,
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to request private chat.")),
+ },
+ },
+ },
+ },
+ {
+ name: "when userA invites userB to new private chat",
+ args: args{
+ cc: &ClientConn{
+ ID: [2]byte{0, 1},
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessOpenChat)
+ return bits
+ }(),
+ },
+ UserName: []byte("UserA"),
+ Icon: []byte{0, 1},
+ Flags: [2]byte{0, 0},
+ Server: &Server{
+ ClientMgr: func() *MockClientMgr {
+ m := MockClientMgr{}
+ m.On("Get", ClientID{0x0, 0x2}).Return(&ClientConn{
+ ID: [2]byte{0, 2},
+ UserName: []byte("UserB"),
+ })
+ return &m
+ }(),
+ ChatMgr: func() *MockChatManager {
+ m := MockChatManager{}
+ m.On("New", mock.AnythingOfType("*hotline.ClientConn")).Return(ChatID{0x52, 0xfd, 0xfc, 0x07})
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranInviteNewChat, [2]byte{0, 1},
+ NewField(FieldUserID, []byte{0, 2}),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 2},
+ Type: [2]byte{0, 0x71},
+ Fields: []Field{
+ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+ NewField(FieldUserName, []byte("UserA")),
+ NewField(FieldUserID, []byte{0, 1}),
+ },
+ },
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,
+ Fields: []Field{
+ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+ NewField(FieldUserName, []byte("UserA")),
+ NewField(FieldUserID, []byte{0, 1}),
+ NewField(FieldUserIconID, []byte{0, 1}),
+ NewField(FieldUserFlags, []byte{0, 0}),
+ },
+ },
+ },
+ },
+ {
+ name: "when userA invites userB to new private chat, but UserB has refuse private chat enabled",
+ args: args{
+ cc: &ClientConn{
+ ID: [2]byte{0, 1},
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessOpenChat)
+ return bits
+ }(),
+ },
+ UserName: []byte("UserA"),
+ Icon: []byte{0, 1},
+ Flags: [2]byte{0, 0},
+ Server: &Server{
+ ClientMgr: func() *MockClientMgr {
+ m := MockClientMgr{}
+ m.On("Get", ClientID{0, 2}).Return(&ClientConn{
+ ID: [2]byte{0, 2},
+ Icon: []byte{0, 1},
+ UserName: []byte("UserB"),
+ Flags: [2]byte{255, 255},
+ })
+ return &m
+ }(),
+ ChatMgr: func() *MockChatManager {
+ m := MockChatManager{}
+ m.On("New", mock.AnythingOfType("*hotline.ClientConn")).Return(ChatID{0x52, 0xfd, 0xfc, 0x07})
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranInviteNewChat, [2]byte{0, 1},
+ NewField(FieldUserID, []byte{0, 2}),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 1},
+ Type: [2]byte{0, 0x68},
+ Fields: []Field{
+ NewField(FieldData, []byte("UserB does not accept private chats.")),
+ NewField(FieldUserName, []byte("UserB")),
+ NewField(FieldUserID, []byte{0, 2}),
+ NewField(FieldOptions, []byte{0, 2}),
+ },
+ },
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,
+ Fields: []Field{
+ NewField(FieldChatID, []byte{0x52, 0xfd, 0xfc, 0x07}),
+ NewField(FieldUserName, []byte("UserA")),
+ NewField(FieldUserID, []byte{0, 1}),
+ NewField(FieldUserIconID, []byte{0, 1}),
+ NewField(FieldUserFlags, []byte{0, 0}),
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+
+ gotRes := HandleInviteNewChat(tt.args.cc, &tt.args.t)
+
+ tranAssertEqual(t, tt.wantRes, gotRes)
+ })
+ }
+}
+
+func TestHandleGetNewsArtData(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ {
+ name: "when user does not have required permission",
+ args: args{
+ cc: &ClientConn{Account: &Account{}},
+ t: NewTransaction(
+ TranGetNewsArtData, [2]byte{0, 1},
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ IsReply: 0x01,
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to read news.")),
+ },
+ },
+ },
+ },
+ {
+ name: "when user has required permission",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessNewsReadArt)
+ return bits
+ }(),
+ },
+ Server: &Server{
+ ThreadedNewsMgr: func() *mockThreadNewsMgr {
+ m := mockThreadNewsMgr{}
+ m.On("GetArticle", []string{"Example Category"}, uint32(1)).Return(&NewsArtData{
+ Title: "title",
+ Poster: "poster",
+ Date: [8]byte{},
+ PrevArt: [4]byte{0, 0, 0, 1},
+ NextArt: [4]byte{0, 0, 0, 2},
+ ParentArt: [4]byte{0, 0, 0, 3},
+ FirstChildArt: [4]byte{0, 0, 0, 4},
+ DataFlav: []byte("text/plain"),
+ Data: "article data",
+ })
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranGetNewsArtData, [2]byte{0, 1},
+ NewField(FieldNewsPath, []byte{
+ // Example Category
+ 0x00, 0x01, 0x00, 0x00, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79,
+ }),
+ NewField(FieldNewsArtID, []byte{0, 1}),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ IsReply: 1,
+ Fields: []Field{
+ NewField(FieldNewsArtTitle, []byte("title")),
+ NewField(FieldNewsArtPoster, []byte("poster")),
+ NewField(FieldNewsArtDate, []byte{0, 0, 0, 0, 0, 0, 0, 0}),
+ NewField(FieldNewsArtPrevArt, []byte{0, 0, 0, 1}),
+ NewField(FieldNewsArtNextArt, []byte{0, 0, 0, 2}),
+ NewField(FieldNewsArtParentArt, []byte{0, 0, 0, 3}),
+ NewField(FieldNewsArt1stChildArt, []byte{0, 0, 0, 4}),
+ NewField(FieldNewsArtDataFlav, []byte("text/plain")),
+ NewField(FieldNewsArtData, []byte("article data")),
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotRes := HandleGetNewsArtData(tt.args.cc, &tt.args.t)
+ tranAssertEqual(t, tt.wantRes, gotRes)
+ })
+ }
+}
+
+func TestHandleGetNewsArtNameList(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ {
+ name: "when user does not have required permission",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ return bits
+ }(),
+ },
+ Server: &Server{
+ //Accounts: map[string]*Account{},
+ },
+ },
+ t: NewTransaction(
+ TranGetNewsArtNameList, [2]byte{0, 1},
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ Flags: 0x00,
+ IsReply: 0x01,
+ Type: [2]byte{0, 0},
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to read news.")),
+ },
+ },
+ },
+ },
+ //{
+ // name: "when user has required access",
+ // args: args{
+ // cc: &ClientConn{
+ // Account: &Account{
+ // Access: func() accessBitmap {
+ // var bits accessBitmap
+ // bits.Set(AccessNewsReadArt)
+ // return bits
+ // }(),
+ // },
+ // Server: &Server{
+ // ThreadedNewsMgr: func() *mockThreadNewsMgr {
+ // m := mockThreadNewsMgr{}
+ // m.On("ListArticles", []string{"Example Category"}).Return(NewsArtListData{
+ // Name: []byte("testTitle"),
+ // NewsArtList: []byte{},
+ // })
+ // return &m
+ // }(),
+ // },
+ // },
+ // t: NewTransaction(
+ // TranGetNewsArtNameList,
+ // [2]byte{0, 1},
+ // // 00000000 00 01 00 00 10 45 78 61 6d 70 6c 65 20 43 61 74 |.....Example Cat|
+ // // 00000010 65 67 6f 72 79 |egory|
+ // NewField(FieldNewsPath, []byte{
+ // 0x00, 0x01, 0x00, 0x00, 0x10, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79,
+ // }),
+ // ),
+ // },
+ // wantRes: []Transaction{
+ // {
+ // IsReply: 0x01,
+ // Fields: []Field{
+ // NewField(FieldNewsArtListData, []byte{
+ // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+ // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ // 0x09, 0x74, 0x65, 0x73, 0x74, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x50,
+ // 0x6f, 0x73, 0x74, 0x65, 0x72, 0x0a, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, 0x61, 0x69, 0x6e,
+ // 0x00, 0x08,
+ // },
+ // ),
+ // },
+ // },
+ // },
+ //},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotRes := HandleGetNewsArtNameList(tt.args.cc, &tt.args.t)
+
+ tranAssertEqual(t, tt.wantRes, gotRes)
+ })
+ }
+}
+
+func TestHandleNewNewsFldr(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ {
+ name: "when user does not have required permission",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ return bits
+ }(),
+ },
+ Server: &Server{
+ //Accounts: map[string]*Account{},
+ },
+ },
+ t: NewTransaction(
+ TranGetNewsArtNameList, [2]byte{0, 1},
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ Flags: 0x00,
+ IsReply: 0x01,
+ Type: [2]byte{0, 0},
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to create news folders.")),
+ },
+ },
+ },
+ },
+ {
+ name: "with a valid request",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessNewsCreateFldr)
+ return bits
+ }(),
+ },
+ logger: NewTestLogger(),
+ ID: [2]byte{0, 1},
+ Server: &Server{
+ ThreadedNewsMgr: func() *mockThreadNewsMgr {
+ m := mockThreadNewsMgr{}
+ m.On("CreateGrouping", []string{"test"}, "testFolder", NewsBundle).Return(nil)
+ return &m
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranGetNewsArtNameList, [2]byte{0, 1},
+ NewField(FieldFileName, []byte("testFolder")),
+ NewField(FieldNewsPath,
+ []byte{
+ 0, 1,
+ 0, 0,
+ 4,
+ 0x74, 0x65, 0x73, 0x74,
+ },
+ ),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ clientID: [2]byte{0, 1},
+ IsReply: 0x01,
+ Fields: []Field{},
+ },
+ },
+ },
+ //{
+ // Name: "when there is an error writing the threaded news file",
+ // args: args{
+ // cc: &ClientConn{
+ // Account: &Account{
+ // Access: func() accessBitmap {
+ // var bits accessBitmap
+ // bits.Set(AccessNewsCreateFldr)
+ // return bits
+ // }(),
+ // },
+ // logger: NewTestLogger(),
+ // Type: [2]byte{0, 1},
+ // Server: &Server{
+ // ConfigDir: "/fakeConfigRoot",
+ // FS: func() *MockFileStore {
+ // mfs := &MockFileStore{}
+ // mfs.On("WriteFile", "/fakeConfigRoot/ThreadedNews.yaml", mock.Anything, mock.Anything).Return(os.ErrNotExist)
+ // return mfs
+ // }(),
+ // ThreadedNews: &ThreadedNews{Categories: map[string]NewsCategoryListData15{
+ // "test": {
+ // Type: []byte{0, 2},
+ // Count: nil,
+ // NameSize: 0,
+ // Name: "test",
+ // SubCats: make(map[string]NewsCategoryListData15),
+ // },
+ // }},
+ // },
+ // },
+ // t: NewTransaction(
+ // TranGetNewsArtNameList, [2]byte{0, 1},
+ // NewField(FieldFileName, []byte("testFolder")),
+ // NewField(FieldNewsPath,
+ // []byte{
+ // 0, 1,
+ // 0, 0,
+ // 4,
+ // 0x74, 0x65, 0x73, 0x74,
+ // },
+ // ),
+ // ),
+ // },
+ // wantRes: []Transaction{
+ // {
+ // clientID: [2]byte{0, 1},
+ // Flags: 0x00,
+ // IsReply: 0x01,
+ // Type: [2]byte{0, 0},
+ // ErrorCode: [4]byte{0, 0, 0, 1},
+ // Fields: []Field{
+ // NewField(FieldError, []byte("Error creating news folder.")),
+ // },
+ // },
+ // },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotRes := HandleNewNewsFldr(tt.args.cc, &tt.args.t)
+
+ tranAssertEqual(t, tt.wantRes, gotRes)
+ })
+ }
+}
+
+func TestHandleDownloadBanner(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotRes := HandleDownloadBanner(tt.args.cc, &tt.args.t)
+
+ assert.Equalf(t, tt.wantRes, gotRes, "HandleDownloadBanner(%v, %v)", tt.args.cc, &tt.args.t)
+ })
+ }
+}
+
+func TestHandlePostNewsArt(t *testing.T) {
+ type args struct {
+ cc *ClientConn
+ t Transaction
+ }
+ tests := []struct {
+ name string
+ args args
+ wantRes []Transaction
+ }{
+ {
+ name: "without required permission",
+ args: args{
+ cc: &ClientConn{
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ return bits
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranPostNewsArt,
+ [2]byte{0, 0},
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ IsReply: 0x01,
+ ErrorCode: [4]byte{0, 0, 0, 1},
+ Fields: []Field{
+ NewField(FieldError, []byte("You are not allowed to post news articles.")),
+ },
+ },
+ },
+ },
+ {
+ name: "with required permission",
+ args: args{
+ cc: &ClientConn{
+ Server: &Server{
+ ThreadedNewsMgr: func() *mockThreadNewsMgr {
+ m := mockThreadNewsMgr{}
+ m.On("PostArticle", []string{"www"}, uint32(0), mock.AnythingOfType("hotline.NewsArtData")).Return(nil)
+ return &m
+ }(),
+ },
+ Account: &Account{
+ Access: func() accessBitmap {
+ var bits accessBitmap
+ bits.Set(AccessNewsPostArt)
+ return bits
+ }(),
+ },
+ },
+ t: NewTransaction(
+ TranPostNewsArt,
+ [2]byte{0, 0},
+ NewField(FieldNewsPath, []byte{0x00, 0x01, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77}),
+ NewField(FieldNewsArtID, []byte{0x00, 0x00, 0x00, 0x00}),
+ ),
+ },
+ wantRes: []Transaction{
+ {
+ IsReply: 0x01,
+ ErrorCode: [4]byte{0, 0, 0, 0},
+ Fields: []Field{},
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tranAssertEqual(t, tt.wantRes, HandlePostNewsArt(tt.args.cc, &tt.args.t))
+ })
+ }
+}