Skip to content

Commit

Permalink
Add test to encode a URL as Base64 as default
Browse files Browse the repository at this point in the history
Complements 9014b01.
  • Loading branch information
dr0i committed Nov 15, 2024
1 parent e49cdd7 commit 8fe3804
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
@ExtendWith(MetafixToDo.Extension.class)
public class MetafixMethodTest {

private static final String YOUTUBE_URL = "https://www.youtube.com/watch?v=daLgsPSvD9A";

@Mock
private StreamReceiver streamReceiver;

Expand Down Expand Up @@ -4085,21 +4087,30 @@ public void shouldTransformStringToBase64() {
}

@Test
public void shouldTransformUrlToBase64() {
public void shouldTransformUrlSafeToBase64() {
urlToBase64(",url_safe:'true'", "aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj1kYUxnc1BTdkQ5QQ==");
}

@Test
public void shouldTransformNotUrlSafeToBase64AsDefault() {
urlToBase64("", "aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kYUxnc1BTdkQ5QQ==");
}

private void urlToBase64(final String option, final String expected) {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"to_base64('data.title', url_safe:'true')"
"to_base64('data.title'" + option + ")"
),
i -> {
i.startRecord("1");
i.startEntity("data");
i.literal("title", "https://www.youtube.com/watch?v=daLgsPSvD9A");
i.literal("title", YOUTUBE_URL);
i.endEntity();
i.endRecord();
},
o -> {
o.get().startRecord("1");
o.get().startEntity("data");
o.get().literal("title", "aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj1kYUxnc1BTdkQ5QQ==");
o.get().literal("title", expected);
o.get().endEntity();
o.get().endRecord();
}
Expand Down

0 comments on commit 8fe3804

Please sign in to comment.