Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NT-1924; Create GraphQL Comment Data Models #1246

Merged
merged 19 commits into from
May 18, 2021

Conversation

sunday-okpoluaefe
Copy link
Contributor

@sunday-okpoluaefe sunday-okpoluaefe commented May 13, 2021

📲 What

Create GraphQL Comment Data Models

🤔 Why

Comment models are created for the Graph QL network calls

🛠 How

  • Created CommentThread class

import auto.parcel.AutoParcel;

@AutoGson
@AutoParcel
public abstract class CommentThread implements Parcelable{
  public abstract User author();
  public abstract String body();
  public abstract DateTime createdAt();
  public abstract Boolean deleted();
  public abstract long id();
  public abstract long parentId();

  @AutoParcel.Builder
  public abstract static class Builder {
    public abstract Builder author(User __);
    public abstract Builder body(String __);
    public abstract Builder createdAt(DateTime __);
    public abstract Builder deleted(Boolean __);
    public abstract Builder id(long __);
    public abstract Builder parentId(long __);
    public abstract CommentThread build();
  }

  public static CommentThread.Builder builder() {
    return new AutoParcel_CommentThread.Builder();
  }

  public abstract CommentThread.Builder toBuilder();

@Override
  public boolean equals(final @Nullable Object obj) {
    boolean equals = super.equals(obj);

    if (obj instanceof CommentThread) {
      final CommentThread other = (CommentThread) obj;
      equals = Objects.equals(this.id(), other.id()) &&
              Objects.equals(this.author(), other.author()) &&
              Objects.equals(this.parentId(), other.parentId());
    }

    return equals;
  }

  @Override
  public int hashCode() {
    return super.hashCode();
  }

}
  • Added unit test
import com.kickstarter.models.CommentThread
import org.joda.time.DateTime

class CommentThreadFactory {

    companion object {
        fun comment(): CommentThread {
            return CommentThread.builder()
                .id(1)
                .author(
                    UserFactory.user()
                        .toBuilder()
                        .id(1)
                        .build()
                )
                .parentId(1)
                .deleted(false)
                .createdAt(DateTime.parse("2021-01-01T00:00:00Z"))
                .body("Some Comment")
                .build()
        }
    }
}

class CommentThreadTest : TestCase() {

fun testEquals_whenSecondCommentThreadDifferentId_returnFalse() {
    val commentA = CommentThreadFactory.comment()
    val commentB = CommentThreadFactory.comment().toBuilder().id(2).build()

    assertFalse(commentA == commentB)
}

fun testEquals_whenSecondCommentThreadDifferentUser_returnFalse() {
    val commentA = CommentThreadFactory.comment()
    val commentB = CommentThreadFactory.comment().toBuilder().author(
        UserFactory.user()
            .toBuilder()
            .id(2)
            .build()
    ).build()

    assertFalse(commentA == commentB)
}

fun testEquals_whenSecondCommentThreadDifferentParentId_returnFalse() {
    val commentA = CommentThreadFactory.comment()
    val commentB = CommentThreadFactory.comment()
        .toBuilder()
        .parentId(2)
        .build()

    assertFalse(commentA == commentB)
}

fun testEquals_whenCommentThreadEquals_returnTrue() {
    val commentA = CommentThreadFactory.comment()
    val commentB = CommentThreadFactory.comment()

    assertTrue(commentA == commentB)
}

}




👀 See

Trello, screenshots, external resources?

Before 🐛 After 🦋

📋 QA

Instructions for anyone to be able to QA this work.

Story 📖

https://kickstarter.atlassian.net/browse/NT-1924

@codecov
Copy link

codecov bot commented May 13, 2021

Codecov Report

Merging #1246 (ba29361) into master (0a5d4ba) will decrease coverage by 0.03%.
The diff coverage is 62.50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1246      +/-   ##
============================================
- Coverage     74.79%   74.76%   -0.04%     
- Complexity      734      740       +6     
============================================
  Files           221      222       +1     
  Lines          6682     6697      +15     
  Branches        403      411       +8     
============================================
+ Hits           4998     5007       +9     
- Misses         1551     1552       +1     
- Partials        133      138       +5     
Impacted Files Coverage Δ Complexity Δ
...arter/mock/factories/DeprecatedCommentFactory.java 100.00% <ø> (ø) 1.00 <0.00> (?)
.../src/main/java/com/kickstarter/models/Comment.java 60.00% <60.00%> (ø) 6.00 <6.00> (?)
...k/factories/DeprecatedCommentsEnvelopeFactory.java 100.00% <100.00%> (ø) 1.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a5d4ba...ba29361. Read the comment docs.

@Arkariang
Copy link
Contributor

Hey @sunday-okpoluaefe ! as it is a draft I'm not sure if I should review it yet but a few comments, feel free to disregard them if you are currently working on this points :).

  • You need to add the equals operator for the class
  • The "authorBadges" field is missing, but I would add that probably as a new field on the User model
  • Add tests specially for the equals operator once it's done :)

@sunday-okpoluaefe
Copy link
Contributor Author

Hey @sunday-okpoluaefe ! as it is a draft I'm not sure if I should review it yet but a few comments, feel free to disregard them if you are currently working on this points :).

  • You need to add the equals operator for the class
  • The "authorBadges" field is missing, but I would add that probably as a new field on the User model
  • Add tests specially for the equals operator once it's done :)

sure thanks

@sunday-okpoluaefe sunday-okpoluaefe marked this pull request as ready for review May 16, 2021 15:08
Sunday Onoriode added 3 commits May 17, 2021 16:28
Copy link
Contributor

@Arkariang Arkariang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change requested

final CommentThread other = (CommentThread) obj;
equals = Objects.equals(this.id(), other.id()) &&
Objects.equals(this.author(), other.author()) &&
Objects.equals(this.parentId(), other.parentId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add all the fields for the Model the next ones are missing
String body();
DateTime createdAt();
Boolean deleted();
String cursor();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

@sunday-okpoluaefe sunday-okpoluaefe merged commit 7766d1b into master May 18, 2021
@sunday-okpoluaefe sunday-okpoluaefe deleted the sunday-nt-1924-comment-data-model branch May 18, 2021 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants