|
| 1 | +using Flow.ConfluenceSearch.ConfluenceClient; |
| 2 | +using Shouldly; |
| 3 | + |
| 4 | +namespace Flow.ConfluenceSearch.Test; |
| 5 | + |
| 6 | +public class ConfluenceQueryBuilderTest |
| 7 | +{ |
| 8 | + [Theory] |
| 9 | + [InlineData( |
| 10 | + "test", |
| 11 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 12 | + )] |
| 13 | + [InlineData( |
| 14 | + "test*", |
| 15 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 16 | + )] |
| 17 | + [InlineData( |
| 18 | + "test example", |
| 19 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (title~\"test* example*\" OR text~\"test* example*\") order by lastmodified DESC" |
| 20 | + )] |
| 21 | + [InlineData( |
| 22 | + "test* example*", |
| 23 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (title~\"test* example*\" OR text~\"test* example*\") order by lastmodified DESC" |
| 24 | + )] |
| 25 | + [InlineData( |
| 26 | + "*test", |
| 27 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (title~\"\\*test*\" OR text~\"\\*test*\") order by lastmodified DESC" |
| 28 | + )] |
| 29 | + [InlineData( |
| 30 | + "\\*+-!():^[]{}~?|&/\"'", |
| 31 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (title~\"\\\\\\*\\+\\-\\!\\(\\)\\:\\^\\[\\]\\{\\}\\~\\?\\|\\&\\/\\\"\\\'*\" OR text~\"\\\\\\*\\+\\-\\!\\(\\)\\:\\^\\[\\]\\{\\}\\~\\?\\|\\&\\/\\\"\\\'*\") order by lastmodified DESC" |
| 32 | + )] |
| 33 | + [InlineData( |
| 34 | + "test #myspace", |
| 35 | + "space IN (myspace) AND type IN(page,blogpost) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 36 | + )] |
| 37 | + [InlineData( |
| 38 | + "test #myspace #yourspace", |
| 39 | + "space IN (myspace,yourspace) AND type IN(page,blogpost) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 40 | + )] |
| 41 | + [InlineData( |
| 42 | + "test @me", |
| 43 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (contributor = currentUser()) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 44 | + )] |
| 45 | + [InlineData( |
| 46 | + "test @john", |
| 47 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (contributor.fullname ~ john) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 48 | + )] |
| 49 | + [InlineData( |
| 50 | + "test @john @me", |
| 51 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND (contributor = currentUser() OR contributor.fullname ~ john) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 52 | + )] |
| 53 | + [InlineData( |
| 54 | + "test +label1", |
| 55 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND label IN (label1) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 56 | + )] |
| 57 | + [InlineData( |
| 58 | + "test +label1 +label2", |
| 59 | + "space IN (AAA,BBB) AND type IN(page,blogpost) AND label IN (label1,label2) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 60 | + )] |
| 61 | + [InlineData( |
| 62 | + "test /", |
| 63 | + "space IN (AAA,BBB) AND type IN(folder) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 64 | + )] |
| 65 | + [InlineData( |
| 66 | + "test .", |
| 67 | + "space IN (AAA,BBB) AND type IN(page) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 68 | + )] |
| 69 | + [InlineData( |
| 70 | + "test \"", |
| 71 | + "space IN (AAA,BBB) AND type IN(blogpost) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 72 | + )] |
| 73 | + [InlineData( |
| 74 | + "test / . \"", |
| 75 | + "space IN (AAA,BBB) AND type IN(folder,blogpost,page) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 76 | + )] |
| 77 | + [InlineData( |
| 78 | + "test *", |
| 79 | + "space IN (AAA,BBB) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 80 | + )] |
| 81 | + [InlineData( |
| 82 | + "test / +label1 @me #myspace @john . +label2 \" #yourspace", |
| 83 | + "space IN (myspace,yourspace) AND type IN(folder,blogpost,page) AND label IN (label1,label2) AND (contributor = currentUser() OR contributor.fullname ~ john) AND (title~\"test*\" OR text~\"test*\") order by lastmodified DESC" |
| 84 | + )] |
| 85 | + public async Task BuildTextCqlTest(string input, string expectedOutput) |
| 86 | + { |
| 87 | + // Act |
| 88 | + var queryBuilder = new ConfluenceQueryBuilder(); |
| 89 | + |
| 90 | + var output = await queryBuilder.BuildTextCql( |
| 91 | + input, |
| 92 | + ["AAA", "BBB"], |
| 93 | + TestContext.Current.CancellationToken |
| 94 | + ); |
| 95 | + |
| 96 | + output.ShouldBe(expectedOutput); |
| 97 | + } |
| 98 | + |
| 99 | + [Theory] |
| 100 | + [InlineData("test", "spaces=AAA,BBB&text=test")] |
| 101 | + [InlineData("test*", "spaces=AAA,BBB&text=test*")] |
| 102 | + [InlineData("test example", "spaces=AAA,BBB&text=test example")] |
| 103 | + [InlineData("test* example*", "spaces=AAA,BBB&text=test* example*")] |
| 104 | + [InlineData("*test", "spaces=AAA,BBB&text=*test")] |
| 105 | + [InlineData( |
| 106 | + "spaces=AAA,BBB&text=\\*+-!():^[]{}~?|&/\"'", |
| 107 | + "spaces=AAA,BBB&text=spaces=AAA,BBB&text=\\*+-!():^[]{}~?|&/\"'" |
| 108 | + )] |
| 109 | + [InlineData("test #myspace", "space=myspace&text=test")] |
| 110 | + [InlineData("test #myspace #yourspace", "space=myspace,yourspace&text=test")] |
| 111 | + [InlineData("test @me", "spaces=AAA,BBB&text=test")] |
| 112 | + [InlineData("test @john", "spaces=AAA,BBB&text=test")] |
| 113 | + [InlineData("test @john @me", "spaces=AAA,BBB&text=test")] |
| 114 | + [InlineData("test +label1", "spaces=AAA,BBB&labels=label1&text=test")] |
| 115 | + [InlineData("test +label1 +label2", "spaces=AAA,BBB&labels=label1,label2&text=test")] |
| 116 | + [InlineData("test /", "spaces=AAA,BBB&type=folder&text=test")] |
| 117 | + [InlineData("test .", "spaces=AAA,BBB&type=page&text=test")] |
| 118 | + [InlineData("test \"", "spaces=AAA,BBB&type=blogpost&text=test")] |
| 119 | + [InlineData("test / . \"", "spaces=AAA,BBB&type=folder&type=blogpost&type=page&text=test")] |
| 120 | + [InlineData("test *", "spaces=AAA,BBB&text=test")] |
| 121 | + [InlineData( |
| 122 | + "test / +label1 @me #myspace @john . +label2 : #yourspace", |
| 123 | + "space=myspace,yourspace&type=folder&type=page&labels=label1,label2&text=test" |
| 124 | + )] |
| 125 | + public async Task BuildQueryForOpenInBrowserTest(string input, string expectedOutput) |
| 126 | + { |
| 127 | + // Act |
| 128 | + var queryBuilder = new ConfluenceQueryBuilder(); |
| 129 | + |
| 130 | + var output = await queryBuilder.BuildQueryForOpenInBrowser( |
| 131 | + input, |
| 132 | + ["AAA", "BBB"], |
| 133 | + TestContext.Current.CancellationToken |
| 134 | + ); |
| 135 | + |
| 136 | + output.ShouldBe(expectedOutput); |
| 137 | + } |
| 138 | +} |
0 commit comments