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

[FEATURE] Add tests for Drifty #618

Open
SaptarshiSarkar12 opened this issue Aug 30, 2024 · 20 comments
Open

[FEATURE] Add tests for Drifty #618

SaptarshiSarkar12 opened this issue Aug 30, 2024 · 20 comments
Assignees
Labels
App 💻 Issues/Pull Requests which update Drifty Application Code EddieHub:good-first-issue Label for good-first-issue finder made by EddieHub Community feature ✨ New feature request or addition good first issue Good for newcomers hacktoberfest Issues/Pull Requests for Hacktoberfest
Milestone

Comments

@SaptarshiSarkar12
Copy link
Owner

SaptarshiSarkar12 commented Aug 30, 2024

Is your feature request related to a problem? Please describe.

It is a tedious task to check if Drifty can still download all the supported types of files like YouTube, and Instagram videos and Spotify songs along with general files like https://download.oracle.com/java/22/latest/jdk-22_linux-x64_bin.deb.

Describe the solution you'd like.

Adding multiple separate JUnit tests (I suppose this would suffice; If you think integration testing would be better in some scenario, please let me know) for each download category, batch processing, etc. would be better. Moreover, these tests can then be run on schedule via GitHub Actions allowing automated testing.

Additional information

If anyone wants to work on this issue, please comment below. I would assign this task to you.

@SaptarshiSarkar12 SaptarshiSarkar12 added feature ✨ New feature request or addition App 💻 Issues/Pull Requests which update Drifty Application Code labels Aug 30, 2024
@SaptarshiSarkar12 SaptarshiSarkar12 added this to the Drifty v2.2.0 milestone Aug 30, 2024
@github-project-automation github-project-automation bot moved this to Todo in Drifty Aug 30, 2024
Copy link
Contributor

Hello 👋! Thank you very much for raising an issue 🙌! The maintainers will get back to you soon for discussion over the issue! 🚀

Meanwhile you can also discuss about the project in our Discord Server 😀

@SaptarshiSarkar12 SaptarshiSarkar12 added help wanted Extra attention and support, and contributors are needed good first issue Good for newcomers EddieHub:good-first-issue Label for good-first-issue finder made by EddieHub Community labels Aug 30, 2024
@SaptarshiSarkar12 SaptarshiSarkar12 pinned this issue Aug 30, 2024
@SaptarshiSarkar12 SaptarshiSarkar12 added the hacktoberfest Issues/Pull Requests for Hacktoberfest label Sep 30, 2024
@JjJjJose
Copy link

JjJjJose commented Oct 2, 2024

hey im currently working on this issue. Is anybody already working on that?

@SaptarshiSarkar12
Copy link
Owner Author

@JjJjJose Hi José 👋!
No one is currently working on this issue. Feel free to work on this issue.
I am assigning this task to you.
Thank you for your interest 😁.

@JjJjJose
Copy link

JjJjJose commented Oct 6, 2024

@SaptarshiSarkar12 hey!
Right now im working on the unit tests and the youtube link is done i think, heres a example

image

it was really a pain in the head ahahaha
i will do eventually the instagram and spotify links and make a note for future contributors for the file

@SaptarshiSarkar12
Copy link
Owner Author

@JjJjJose Great 😃. Are you testing the link type? Are you using the LinkType class?
The outcome looks good and informative which is useful for debugging purposes.

@JjJjJose
Copy link

JjJjJose commented Oct 6, 2024

i was using indirectly, actually i was using DownloadConfiguration class. i will use the LinkType class for tests!

and thank you !!! :D
Junit is really simple to understand but never got my hands on big projects like that

@SaptarshiSarkar12
Copy link
Owner Author

Yeah, you can use Link type class for that purpose.

Junit is really simple to understand

That's true 😁

...but never got my hands on big projects like that

I hope you would enjoy working in this project on this issue gaining enough experience to work on more such big projects 😃.

@JjJjJose
Copy link

JjJjJose commented Oct 6, 2024

really appreciate it 😄

if you have any extra info about the link Type class feel free to comment!

@SaptarshiSarkar12
Copy link
Owner Author

@JjJjJose The class is self explanatory, I suppose. Nothing more to tell 😄. If you don't understand any usage/method, you can comment.

@JjJjJose
Copy link

JjJjJose commented Oct 6, 2024

when i try to implement the class the test keeps on a infinite loop, any idea how to fix it?

@SaptarshiSarkar12
Copy link
Owner Author

Show me the code

@JjJjJose
Copy link

JjJjJose commented Oct 6, 2024

hello, sorry for the delay i was busy

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import support.DownloadConfiguration;
import support.Job;
import utils.MessageBroker;
import utils.Utility;
import init.Environment;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DownloadConfigurationTest {
    private DownloadConfiguration downloadConfiguration;
    private Job testJob;
    private MessageBroker testMessageBroker;

    @BeforeEach
    public void setUp() {
        testMessageBroker = new MessageBroker()
        {
            @Override
            public void msgLinkInfo(String message)
            {
                System.out.println("Info: " + message);
            }
            @Override
            public void msgLinkError(String message)
            {
                System.out.println("Error :" + message);
            }

        };
        //need these things below idk why
        Environment.setMessageBroker(testMessageBroker);

        Utility.initializeUtility();

        /* downloadConfiguration = new DownloadConfiguration("https://example.com", "/downloads", "exampleFile"); */

        /**testJob = new Job("https://example.com", "/downloads", "examplefile", null);
        testMessageBroker = new MessageBroker() {
            // Implement necessary methods if any
        };
        downloadConfiguration = new DownloadConfiguration("https://example.com", "/downloads", "exampleFile");**/
    }

    @Test
    public void testYoutubeDownload() {

        // Simulate the behavior of Utility.getYtDlpMetadata
        //String sampleJsonResponse = "{ \"entries\": [{ \"url\": \"https://youtube.com/video1\", \"title\": \"Video 1\" }] }";
        downloadConfiguration = new DownloadConfiguration("https://www.youtube.com/video1", "/downloads", "exampleFile");

        // Inject the utility instance into the DownloadConfiguration if necessary
        // Assuming DownloadConfiguration uses Utility.getYtDlpMetadata internally

        int statusCode = downloadConfiguration.fetchFileData();
        // Verify the expected behavior
        assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
        assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
        assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
        assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
        assertEquals("https://youtube.com/video1", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
        assertEquals("Video 1.mp4", downloadConfiguration.getFileData().get(0).get("filename"), "The filename should match the expected value.");
    }
    @Test
    public void testInstagramDownload()
    {
        downloadConfiguration = new DownloadConfiguration("https://instagram.com/p/abc123", "/downloads", "exampleFileITG");
        int statusCode = downloadConfiguration.fetchFileData();
        assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
        assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
        assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
        assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
        assertEquals("https://instagram.com/p/abc123", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
    }

    @Test
    public void testSpotifyDownload()
    {
        downloadConfiguration = new DownloadConfiguration("https://open.spotify.com/track/abc123", "/downloads", "examplefileSPTF");
        int statusCode = downloadConfiguration.fetchFileData();
        assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
        assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
        assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
        assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
        assertEquals("https://open.spotify.com/track/abc123", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
    }
    @Test
    public void testOtherLinkDownload()
    {
        downloadConfiguration = new DownloadConfiguration("https://sillynessCode.com", "/downloads", "sillyExample");
        int statusCode = downloadConfiguration.fetchFileData();
        assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
        assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
        assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
        assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
        assertEquals("https://sillynessCode.com", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
    }
}

@SaptarshiSarkar12
Copy link
Owner Author

hello, sorry for the delay i was busy

@JjJjJose it's fine 😃.

From your code, it is clear that you're mixing things up. You are testing DownloadConfiguration class and the download process in the same test class.
I suggest you to break down the test classes with the minimum work. For example, you can create test classes in Core module to test the Environment class, LinkType class, UnitConverter class, DownloadConfiguration class, etc. Then, creating the test classes in CLI module, for any specific class like you can check if theMessageBroker passed to CLI isinstanceOf CLI.MessageBroker.

You can check this branch to get more idea about the point I'm emphasising. The branch hasn't been updated for a long time and is just a trial of how tests can be integrated in this project. I hope it helps you in understanding the procedure I mentioned. Please let me know if you have understood this or have any question.

@JjJjJose
Copy link

JjJjJose commented Oct 8, 2024

oh that helps a lot thanks man!
sorry for the trouble ahahaha, i will be looking in the next few days, if i got any questions i post here!

@SaptarshiSarkar12 SaptarshiSarkar12 removed the help wanted Extra attention and support, and contributors are needed label Oct 8, 2024
@SaptarshiSarkar12
Copy link
Owner Author

oh that helps a lot thanks man!

Happy to see that my trials are of some help to you 😁.

sorry for the trouble ahahaha

@JjJjJose It's fine 🙂. I should have told earlier 😅.

i will be looking in the next few days, if i got any questions i post here!

Alright 👍.

@SaptarshiSarkar12
Copy link
Owner Author

@JjJjJose How far did you progress? Have you faced any problem? Please let me know 😃.

@JjJjJose
Copy link

JjJjJose commented Oct 18, 2024

@SaptarshiSarkar12 im studyng for some exams and didnt have time progress it properly, i will look it eventually. sorry

@SaptarshiSarkar12
Copy link
Owner Author

@JjJjJose It's okay. You can take your time. All the best for your exam 😄.

@SaptarshiSarkar12
Copy link
Owner Author

@JjJjJose Did your exam finish? If yes, how was your exam?

@SaptarshiSarkar12
Copy link
Owner Author

@JjJjJose Please reply. Did you encounter any problems?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App 💻 Issues/Pull Requests which update Drifty Application Code EddieHub:good-first-issue Label for good-first-issue finder made by EddieHub Community feature ✨ New feature request or addition good first issue Good for newcomers hacktoberfest Issues/Pull Requests for Hacktoberfest
Projects
Status: Todo
Development

No branches or pull requests

2 participants