|
6 | 6 | use function Pest\Laravel\getJson; |
7 | 7 |
|
8 | 8 | beforeEach(function () { |
9 | | - config(['log-viewer.include_files' => ['*.log']]); |
| 9 | + config(['log-viewer.include_files' => ['*.log', '*/**.log']]); |
10 | 10 | }); |
11 | 11 |
|
12 | | -describe('FilesController with invalid sorting values', function () { |
13 | | - it('returns files with default desc order when invalid direction is provided', function () { |
14 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
15 | | - $names = ['one.log', 'two.log', 'three.log']; |
16 | | - generateLogFiles($names, randomContent: true); |
17 | | - |
18 | | - array_map(function (string $name) { |
19 | | - $this->travelTo(now()->addSecond()); |
20 | | - touch(storage_path('logs/'.$name), now()->timestamp); |
21 | | - }, $names); |
22 | | - |
23 | | - $response = getJson(route('log-viewer.files', ['direction' => 'invalid'])); |
24 | | - |
25 | | - expect(array_column($response->json(), 'name'))->toBe([ |
26 | | - 'three.log', |
27 | | - 'two.log', |
28 | | - 'one.log', |
29 | | - ]); |
30 | | - }); |
31 | | - |
32 | | - it('returns files with default desc order when empty direction is provided', function () { |
33 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
34 | | - $names = ['one.log', 'two.log', 'three.log']; |
35 | | - generateLogFiles($names, randomContent: true); |
36 | | - |
37 | | - array_map(function (string $name) { |
38 | | - $this->travelTo(now()->addSecond()); |
39 | | - touch(storage_path('logs/'.$name), now()->timestamp); |
40 | | - }, $names); |
41 | | - |
42 | | - $response = getJson(route('log-viewer.files', ['direction' => ''])); |
43 | | - |
44 | | - expect(array_column($response->json(), 'name'))->toBe([ |
45 | | - 'three.log', |
46 | | - 'two.log', |
47 | | - 'one.log', |
48 | | - ]); |
49 | | - }); |
50 | | - |
51 | | - it('returns files with default desc order when direction is null', function () { |
52 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
53 | | - $names = ['one.log', 'two.log', 'three.log']; |
54 | | - generateLogFiles($names, randomContent: true); |
55 | | - |
56 | | - array_map(function (string $name) { |
57 | | - $this->travelTo(now()->addSecond()); |
58 | | - touch(storage_path('logs/'.$name), now()->timestamp); |
59 | | - }, $names); |
60 | | - |
61 | | - $response = getJson(route('log-viewer.files')); |
62 | | - |
63 | | - expect(array_column($response->json(), 'name'))->toBe([ |
64 | | - 'three.log', |
65 | | - 'two.log', |
66 | | - 'one.log', |
67 | | - ]); |
68 | | - }); |
69 | | - |
70 | | - it('returns files with alphabetical sorting and default desc when invalid direction is provided', function () { |
71 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::Alphabetical]); |
72 | | - generateLogFiles(['one.log', 'two.log', 'three.log', 'four.log'], randomContent: true); |
73 | | - |
74 | | - $response = getJson(route('log-viewer.files', ['direction' => 'invalid'])); |
75 | | - |
76 | | - expect(array_column($response->json(), 'name'))->toBe([ |
77 | | - 'two.log', |
78 | | - 'three.log', |
79 | | - 'one.log', |
80 | | - 'four.log', |
81 | | - ]); |
82 | | - }); |
83 | | - |
84 | | - it('returns files in correct order with valid asc direction and alphabetical sorting', function () { |
85 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::Alphabetical]); |
86 | | - generateLogFiles(['one.log', 'two.log', 'three.log', 'four.log'], randomContent: true); |
87 | | - |
88 | | - $response = getJson(route('log-viewer.files', ['direction' => SortingOrder::Ascending])); |
89 | | - |
90 | | - expect(array_column($response->json(), 'name'))->toBe([ |
91 | | - 'four.log', |
92 | | - 'one.log', |
93 | | - 'three.log', |
94 | | - 'two.log', |
95 | | - ]); |
96 | | - }); |
| 12 | +// FilesController with invalid sorting values |
| 13 | + |
| 14 | +it('files controller returns default desc order when invalid direction is provided', function () { |
| 15 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
| 16 | + $names = ['one.log', 'two.log', 'three.log']; |
| 17 | + generateLogFiles($names, randomContent: true); |
| 18 | + |
| 19 | + array_map(function (string $name) { |
| 20 | + $this->travelTo(now()->addSecond()); |
| 21 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 22 | + }, $names); |
| 23 | + |
| 24 | + $response = getJson(route('log-viewer.files', ['direction' => 'invalid'])); |
| 25 | + |
| 26 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 27 | + 'three.log', |
| 28 | + 'two.log', |
| 29 | + 'one.log', |
| 30 | + ]); |
| 31 | +}); |
| 32 | + |
| 33 | +it('files controller returns default desc order when empty direction is provided', function () { |
| 34 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
| 35 | + $names = ['one.log', 'two.log', 'three.log']; |
| 36 | + generateLogFiles($names, randomContent: true); |
| 37 | + |
| 38 | + array_map(function (string $name) { |
| 39 | + $this->travelTo(now()->addSecond()); |
| 40 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 41 | + }, $names); |
| 42 | + |
| 43 | + $response = getJson(route('log-viewer.files', ['direction' => ''])); |
| 44 | + |
| 45 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 46 | + 'three.log', |
| 47 | + 'two.log', |
| 48 | + 'one.log', |
| 49 | + ]); |
| 50 | +}); |
| 51 | + |
| 52 | +it('files controller returns default desc order when direction is null', function () { |
| 53 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
| 54 | + $names = ['one.log', 'two.log', 'three.log']; |
| 55 | + generateLogFiles($names, randomContent: true); |
| 56 | + |
| 57 | + array_map(function (string $name) { |
| 58 | + $this->travelTo(now()->addSecond()); |
| 59 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 60 | + }, $names); |
| 61 | + |
| 62 | + $response = getJson(route('log-viewer.files')); |
| 63 | + |
| 64 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 65 | + 'three.log', |
| 66 | + 'two.log', |
| 67 | + 'one.log', |
| 68 | + ]); |
| 69 | +}); |
| 70 | + |
| 71 | +it('files controller returns alphabetical sorting with default desc when invalid direction is provided', function () { |
| 72 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::Alphabetical]); |
| 73 | + generateLogFiles(['one.log', 'two.log', 'three.log', 'four.log'], randomContent: true); |
| 74 | + |
| 75 | + $response = getJson(route('log-viewer.files', ['direction' => 'invalid'])); |
| 76 | + |
| 77 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 78 | + 'two.log', |
| 79 | + 'three.log', |
| 80 | + 'one.log', |
| 81 | + 'four.log', |
| 82 | + ]); |
| 83 | +}); |
| 84 | + |
| 85 | +it('files controller returns correct order with valid asc direction and alphabetical sorting', function () { |
| 86 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::Alphabetical]); |
| 87 | + generateLogFiles(['one.log', 'two.log', 'three.log', 'four.log'], randomContent: true); |
| 88 | + |
| 89 | + $response = getJson(route('log-viewer.files', ['direction' => SortingOrder::Ascending])); |
| 90 | + |
| 91 | + expect(array_column($response->json(), 'name'))->toBe([ |
| 92 | + 'four.log', |
| 93 | + 'one.log', |
| 94 | + 'three.log', |
| 95 | + 'two.log', |
| 96 | + ]); |
97 | 97 | }); |
98 | 98 |
|
99 | | -describe('FoldersController with invalid sorting values', function () { |
100 | | - beforeEach(function () { |
101 | | - config(['log-viewer.include_files' => ['*/**.log']]); |
102 | | - }); |
103 | | - |
104 | | - it('returns folders with files in default desc order when invalid direction is provided', function () { |
105 | | - config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
106 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
107 | | - $names = ['sub/one.log', 'sub/two.log', 'sub/three.log']; |
108 | | - generateLogFiles($names, randomContent: true); |
109 | | - |
110 | | - array_map(function (string $name) { |
111 | | - $this->travelTo(now()->addSecond()); |
112 | | - touch(storage_path('logs/'.$name), now()->timestamp); |
113 | | - }, $names); |
114 | | - |
115 | | - $response = getJson(route('log-viewer.folders', ['direction' => 'invalid'])); |
116 | | - |
117 | | - expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
118 | | - 'three.log', |
119 | | - 'two.log', |
120 | | - 'one.log', |
121 | | - ]); |
122 | | - }); |
123 | | - |
124 | | - it('returns folders with files in default desc order when empty direction is provided', function () { |
125 | | - config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
126 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
127 | | - $names = ['sub/one.log', 'sub/two.log', 'sub/three.log']; |
128 | | - generateLogFiles($names, randomContent: true); |
129 | | - |
130 | | - array_map(function (string $name) { |
131 | | - $this->travelTo(now()->addSecond()); |
132 | | - touch(storage_path('logs/'.$name), now()->timestamp); |
133 | | - }, $names); |
134 | | - |
135 | | - $response = getJson(route('log-viewer.folders', ['direction' => ''])); |
136 | | - |
137 | | - expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
138 | | - 'three.log', |
139 | | - 'two.log', |
140 | | - 'one.log', |
141 | | - ]); |
142 | | - }); |
143 | | - |
144 | | - it('returns folders with files in default desc order when direction is null', function () { |
145 | | - config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
146 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
147 | | - $names = ['sub/one.log', 'sub/two.log', 'sub/three.log']; |
148 | | - generateLogFiles($names, randomContent: true); |
149 | | - |
150 | | - array_map(function (string $name) { |
151 | | - $this->travelTo(now()->addSecond()); |
152 | | - touch(storage_path('logs/'.$name), now()->timestamp); |
153 | | - }, $names); |
154 | | - |
155 | | - $response = getJson(route('log-viewer.folders')); |
156 | | - |
157 | | - expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
158 | | - 'three.log', |
159 | | - 'two.log', |
160 | | - 'one.log', |
161 | | - ]); |
162 | | - }); |
163 | | - |
164 | | - it('returns folders with files in correct order with valid asc direction and alphabetical sorting', function () { |
165 | | - config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
166 | | - config(['log-viewer.defaults.file_sorting_method' => SortingMethod::Alphabetical]); |
167 | | - generateLogFiles(['sub/one.log', 'sub/two.log', 'sub/three.log', 'sub/four.log'], randomContent: true); |
168 | | - |
169 | | - $response = getJson(route('log-viewer.folders', ['direction' => SortingOrder::Ascending])); |
170 | | - |
171 | | - expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
172 | | - 'four.log', |
173 | | - 'one.log', |
174 | | - 'three.log', |
175 | | - 'two.log', |
176 | | - ]); |
177 | | - }); |
| 99 | +// FoldersController with invalid sorting values |
| 100 | + |
| 101 | +it('folders controller returns default desc order when invalid direction is provided', function () { |
| 102 | + config(['log-viewer.include_files' => ['*/**.log']]); |
| 103 | + config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
| 104 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
| 105 | + $names = ['sub/one.log', 'sub/two.log', 'sub/three.log']; |
| 106 | + generateLogFiles($names, randomContent: true); |
| 107 | + |
| 108 | + array_map(function (string $name) { |
| 109 | + $this->travelTo(now()->addSecond()); |
| 110 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 111 | + }, $names); |
| 112 | + |
| 113 | + $response = getJson(route('log-viewer.folders', ['direction' => 'invalid'])); |
| 114 | + |
| 115 | + expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
| 116 | + 'three.log', |
| 117 | + 'two.log', |
| 118 | + 'one.log', |
| 119 | + ]); |
| 120 | +}); |
| 121 | + |
| 122 | +it('folders controller returns default desc order when empty direction is provided', function () { |
| 123 | + config(['log-viewer.include_files' => ['*/**.log']]); |
| 124 | + config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
| 125 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
| 126 | + $names = ['sub/one.log', 'sub/two.log', 'sub/three.log']; |
| 127 | + generateLogFiles($names, randomContent: true); |
| 128 | + |
| 129 | + array_map(function (string $name) { |
| 130 | + $this->travelTo(now()->addSecond()); |
| 131 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 132 | + }, $names); |
| 133 | + |
| 134 | + $response = getJson(route('log-viewer.folders', ['direction' => ''])); |
| 135 | + |
| 136 | + expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
| 137 | + 'three.log', |
| 138 | + 'two.log', |
| 139 | + 'one.log', |
| 140 | + ]); |
| 141 | +}); |
| 142 | + |
| 143 | +it('folders controller returns default desc order when direction is null', function () { |
| 144 | + config(['log-viewer.include_files' => ['*/**.log']]); |
| 145 | + config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
| 146 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::ModifiedTime]); |
| 147 | + $names = ['sub/one.log', 'sub/two.log', 'sub/three.log']; |
| 148 | + generateLogFiles($names, randomContent: true); |
| 149 | + |
| 150 | + array_map(function (string $name) { |
| 151 | + $this->travelTo(now()->addSecond()); |
| 152 | + touch(storage_path('logs/'.$name), now()->timestamp); |
| 153 | + }, $names); |
| 154 | + |
| 155 | + $response = getJson(route('log-viewer.folders')); |
| 156 | + |
| 157 | + expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
| 158 | + 'three.log', |
| 159 | + 'two.log', |
| 160 | + 'one.log', |
| 161 | + ]); |
| 162 | +}); |
| 163 | + |
| 164 | +it('folders controller returns correct order with valid asc direction and alphabetical sorting', function () { |
| 165 | + config(['log-viewer.include_files' => ['*/**.log']]); |
| 166 | + config(['log-viewer.defaults.folder_sorting_method' => SortingMethod::Alphabetical]); |
| 167 | + config(['log-viewer.defaults.file_sorting_method' => SortingMethod::Alphabetical]); |
| 168 | + generateLogFiles(['sub/one.log', 'sub/two.log', 'sub/three.log', 'sub/four.log'], randomContent: true); |
| 169 | + |
| 170 | + $response = getJson(route('log-viewer.folders', ['direction' => SortingOrder::Ascending])); |
| 171 | + |
| 172 | + expect(array_column($response->json()[0]['files'], 'name'))->toBe([ |
| 173 | + 'four.log', |
| 174 | + 'one.log', |
| 175 | + 'three.log', |
| 176 | + 'two.log', |
| 177 | + ]); |
178 | 178 | }); |
0 commit comments