Planning Repost Tests0:00
Let's do some reposting. Creating reposts is a lot like creating replies. It's just another Post. We just have to change, you know, different column values in the database. So I'm gonna copy the test for creating a reply. And here we'll say create plain repost because we have two types of reposts. We have the plain repost and then we have one that has content that goes with it.
We have the plain repost and then we have one that has content that goes with it. But you know, conceptually it's gonna be the same thing. So that we have our original post, we don't have a reply, we have a repost profile that we are going to send to the, uh, let's just call it repost method. And this is going to give us a repost so that we pass them the repost profile, the original post to, you know, repost. But we don't have any content with it.
Adding Repost Relationship1:00
to, you know, repost. But we don't have any content with it. It's a plain, ordinary repost. So that's it. And then we want to expect that the repost, it's not parent, what do we use for the, uh, relationship there? We have reposts, but we don't have the reverse. We need to create that. Um, we can't call it repost because we are going to have
Um, we can't call it repost because we are going to have that static method called repost. So for the lack of a better word, we're gonna use repost, we can always come back and change it if we need to. And this is belongsTo so that it returns. This belongsTo Post class and then repost of id. So we have that repost relationship now, so that the repost is the original.
So we have that repost of relationship now, so that the repost repost of is the original. That should be true. And then the original not replies, reposts to have account of one. But this is a plain repost. We also need to check to be sure that the repost content to be null. Okay, there's our test. Let's run them. This is what? The fifth test? Uh, no, it's the fourth, but it failed. And why did it fail?
Implementing Repost Method2:25
The fifth test? Uh, no, it's the fourth, but it failed. And why did it fail? Well call to undefined method. Repost. Of course it did. 'cause we didn't implement that method. Duh. Okay, so let's just copy what we have for reply because it is essentially going to be the same thing except, uh, I don't wanna have different methods for creating different kinds of reposts. I want just one. So what we're going to do is set a
I want just one. So what we're going to do is set a default value for content. It'll be null, and then we can supply content. And then we will have a quoteRepost. All right, so the profileId, the content is set to content, and in this case, the parentId is null. And the repostId is the original id. So let's run our test now and let's see what we get. It still fails,
Debugging Failed Relationship3:24
So let's run our test now and let's see what we get. It still fails, but let's see, repost of is original that failed. But it says call to member function is on null. So we called is on repost. So repost or repost of, so repost of is null. So what does that mean? We have a repost. Because if, if we didn't have a repost or,
We have a repost. Because if, if we didn't have a repost or, or at least the post was created for the repost, because if we didn't, then we would've gotten a different error message saying something about this repost variable here, saying that it was null Or saying that it was something. So we have a repost. It's just that repost of is null. So let's go to our model class. Let's look at the relationship.
So let's go to our model class. Let's look at the relationship. It's hasMany that, that's fine. So whenever we repost the profile_id is the profile_id. The content is the content. The parent_id is null. So it's not a reply. And the repost_id is the original_id. So all that's right. But for whatever reason, this relationship is not getting set,
Testing Multiple Reposts4:50
So all that's right. But for whatever reason, this relationship is not getting set, which means fillable. Yep. Okay, That's gonna make that work. Fingers crossed. We should have four passed. Yes. Okay. So now I want to essentially do the same thing that we did with the replies to test if we can have multiple reposts. So let's copy what we did for the replies and we can have many reposts so that we have our original,
So let's copy what we did for the replies and we can have many reposts so that we have our original, but these are gonna be reposts. Let's see, I'm, I think we have a repost method in our factory. Let's check that out to be sure. We have quote posts. We have reposts. Yep. So we'll be fine there to create multiple reposts for the original and we will create them so that the first repost is not the parent, it is the repost of,
for the original and we will create them so that the first repost is not the parent, it is the repost of, is the original to be true. The replies? No, we want reposts to have a count of four. The original reposts contains the first repost. So this should be true. Let's run it again. We should have five passing tests. We have five, right? So now I want a quote repost. So let's copy this.
Creating Quote Reposts6:22
So now I want a quote repost. So let's copy this. Hopefully intelligence won't get in my way and thankfully it didn't. All right, so now we are going to create a quote repost. And the only difference here is that we have some actual content. So it'll say that the quoteContent is gonna be the content. Then instead of checking to see if it is null, we will just check to see if it is our
Then instead of checking to see if it is null, we will just check to see if it is our quoteContent. And I guess to be, you know, exact here, we need to set content equal to quoteContent. That way we, we don't mess up with any strings. And of course this is a simple string, but you know, I want to be short here. So we will have our content variable there and our content variable there.
So we will have our content variable there and our content variable there. So we have five passing. Hopefully we will have six passing because all we did is add some content. Sure enough that passes. So now we have the basic functionality of creating reposts. Now we need to be sure that one Profile can repost one Post only one time. Basically we don't want any duplicate reposts.
one post only one time. Basically we don't want any duplicate reposts. So we will tackle that in the next episode.
