wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
337 stars 129 forks source link

added trash status (for post/page) #206

Closed tamper2 closed 3 years ago

tamper2 commented 4 years ago

Found out this was missing, fixed for my project and shared :) As per issue #177

ThomasPe commented 4 years ago

Thanks a lot! Would you be able to add a test for this?

tamper2 commented 4 years ago

Sure, I'll do that. Any requests for the test?

On Mon, 15 Jun 2020, 18:41 Thomas Pentenrieder, notifications@github.com wrote:

Thanks a lot! Would you be able to add a test for this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wp-net/WordPressPCL/pull/206#issuecomment-644211804, or unsubscribe https://github.com/notifications/unsubscribe-auth/APOOAXOLKLKHV5LHZC7IKUTRWY6JDANCNFSM4N6IOTUA .

ThomasPe commented 4 years ago

Nothing special, just check that the correct status is read after deleting / moving a post to trash.

tamper2 commented 4 years ago

Running the hosted & selfhosted tests coming with the original project (without my commit) – most tests fail…?

Am I doing something wrong? I’d prefer to start with a clean slate to know that my tests are running properly…

Image attached:

Description: https://puu.sh/FXKPV/a4b071b547.png

From: Thomas Pentenrieder [mailto:notifications@github.com] Sent: Tuesday, June 16, 2020 16:37 To: wp-net/WordPressPCL Cc: tamper2; Author Subject: Re: [wp-net/WordPressPCL] added trash status (for post/page) (#206)

Nothing special, just check that the correct status is read after deleting / moving a post to trash.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wp-net/WordPressPCL/pull/206#issuecomment-644770619 , or unsubscribe https://github.com/notifications/unsubscribe-auth/APOOAXKRNYWYBYAX6F33H3TRW5YPZANCNFSM4N6IOTUA . https://github.com/notifications/beacon/APOOAXPBHNOR6MCKTEWRE23RW5YPZA5CNFSM4N6IOTUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEZXGWOY.gif

ThomasPe commented 4 years ago

huh, at least the Selfhosted should all pass with a properly configured test environment. I need to check what's happening with those in the PR pipeline

tamper2 commented 4 years ago

huh, at least the Selfhosted should all pass with a properly configured test environment. I need to check what's happening with those in the PR pipeline

Okay, let me know and I'll try to implement those tests later on.

ThomasPe commented 4 years ago

I fixed the ci/cd pipeline, for some reason the wordpress docker container that the tests are run against wasn't created properly.

tamper2 commented 4 years ago

I fixed the ci/cd pipeline, for some reason the wordpress docker container that the tests are run against wasn't created properly.

Still doesn't work for me in my PR, the tests still fail... :( The PR also shows "All checks have failed" regarding WordpressPCL Integration Tests...

ThomasPe commented 4 years ago

I don't think the pipeline has re-run for this PR after I fixed it. Not sure if there's a way to trigger it besides pushing new changes to this branch.

Edit: found it, lets see

ThomasPe commented 4 years ago

test seems to run fine now so you can try adding new Unit Tests and letting them run here if you can't make it work locally.

tamper2 commented 3 years ago

Sorry! I completely forgot about this... I'll try to get around to creating a test next week. I'm still not entirely familiar with the project's way of unit testing so it may take me a while. Got any pointers?

ThomasPe commented 3 years ago

I'm not quite sure in which situations the trash status would be visible, but you can take a look here how the integration tests for posts are set up: https://github.com/wp-net/WordPressPCL/blob/master/WordPressPCL.Tests.Selfhosted/Posts_Tests.cs

Best way would be to create a lokal WordPress instance and having the Selfhosted tests run against that by updating the ApiCredentials: https://github.com/wp-net/WordPressPCL/blob/master/WordPressPCL.Tests.Selfhosted/Utility/ApiCredentials.cs

tamper2 commented 3 years ago

I'm sorry, I'm still rather new to testing in C#, and I can't open a local WP instance on my PC.

Regarding the use-case: In my app I want to let the users restore posts that were previously deleted by them by listing posts with status 'trash'. Would something like this be an appropriate test?

        [TestMethod]
        public async Task Posts_Trash_Query()
        {
            var queryBuilder = new PostsQueryBuilder()
            {
                Statuses = new Status[] { Status.Trash },
            };
            var posts = await _clientAuth.Posts.Query(queryBuilder, true);
            Assert.AreEqual(queryBuilder.BuildQueryURL(), "?status=trash");
            Assert.IsNotNull(posts);
            Assert.AreNotEqual(posts.Count(), 0);
        }

This would of course require having a trashed post in the testing environment. Would you like me to setup that inside the testing method too? (creating & trashing a post -> testing -> deleting post completely)

ThomasPe commented 3 years ago

I would split this into two tests - one to check the QueryBuilder where you don't actually have to make any server calls (your Assert.AreEqual(queryBuilder.BuildQueryURL(), "?status=trash"); line) And the second one as you described, creating a post, trashing it and then checking if it's actually trashed.

tamper2 commented 3 years ago

Can you actually attempt to implement the test? As I'm having issues doing it locally... :(

ThomasPe commented 3 years ago

added tests :) https://github.com/wp-net/WordPressPCL/pull/240