SaptarshiSarkar12 / Drifty

Drifty is an Open-Source Interactive File Downloader System built with Java
https://saptarshisarkar12.github.io/Drifty/
Apache License 2.0
176 stars 130 forks source link

[FEATURE] Add tests for Drifty #618

Open SaptarshiSarkar12 opened 2 months ago

SaptarshiSarkar12 commented 2 months ago

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.

github-actions[bot] commented 2 months ago

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 😀

JjJjJose commented 1 month ago

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

SaptarshiSarkar12 commented 1 month ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

@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 commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

really appreciate it 😄

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

SaptarshiSarkar12 commented 3 weeks ago

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

JjJjJose commented 3 weeks ago

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

SaptarshiSarkar12 commented 3 weeks ago

Show me the code

JjJjJose commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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 commented 2 weeks ago

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

JjJjJose commented 2 weeks ago

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

SaptarshiSarkar12 commented 2 weeks ago

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

SaptarshiSarkar12 commented 5 days ago

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