Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func TestCanCountTheTweetsSentByAnUser(t *testing.T) {
- // Initialization
- service.InitializeService()
- var tweet, secondTweet, thirdTweet *domain.Tweet
- user := "grupoesfera"
- anotherUser := "nick"
- text := "This is my first tweet"
- secondText := "This is my second tweet"
- tweet = domain.NewTweet(user, text)
- secondTweet = domain.NewTweet(user, secondText)
- thirdTweet = domain.NewTweet(anotherUser, text)
- service.PublishTweet(tweet)
- service.PublishTweet(secondTweet)
- service.PublishTweet(thirdTweet)
- // Operation
- count := service.CountTweetsByUser(user)
- // Validation
- if count != 2 {
- t.Errorf("Expected count is 2 but was %d", count)
- }
- }
- func TestCanRetrieveTheTweetsSentByAnUser(t *testing.T) {
- // Initialization
- service.InitializeService()
- var tweet, secondTweet, thirdTweet *domain.Tweet
- user := "grupoesfera"
- anotherUser := "nick"
- text := "This is my first tweet"
- secondText := "This is my second tweet"
- tweet = domain.NewTweet(user, text)
- secondTweet = domain.NewTweet(user, secondText)
- thirdTweet = domain.NewTweet(anotherUser, text)
- firstId, _ := service.PublishTweet(tweet)
- secondId, _ := service.PublishTweet(secondTweet)
- service.PublishTweet(thirdTweet)
- // Operation
- tweets := service.GetTweetsByUser(user)
- // Validation
- if len(tweets) != 2 {
- t.Errorf("Expected size is 2 but was %d", len(tweets))
- return
- }
- firstPublishedTweet := tweets[0]
- secondPublishedTweet := tweets[1]
- if !isValidTweet(t, firstPublishedTweet, firstId, user, text) {
- return
- }
- if !isValidTweet(t, secondPublishedTweet, secondId, user, secondText) {
- return
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement