Skip to content

Commit

Permalink
allow viewing user detail without auth
Browse files Browse the repository at this point in the history
  • Loading branch information
codekeyz committed Jan 6, 2024
1 parent 86164a9 commit 343cfa3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/app/providers/provide_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class RouteServiceProvider extends ServiceProvider {
Route.post('/auth/login', (AuthController, #login)),
Route.post('/auth/register', (AuthController, #register)),

// get articless and detail without auth
Route.group('/articles').routes([
/// get user detail without auth
Route.get('/users/<userId>', (UserController, #show)),

/// get articles and detail without auth
Route.group('articles').routes([
Route.get('/', (ArticleController, #index)),
Route.get('/<articleId>', (ArticleController, #show)),
]),
Expand Down
1 change: 0 additions & 1 deletion lib/app/routes/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ List<RouteDefinition> routes = [
Route.group('users').routes([
Route.get('/', (UserController, #index)),
Route.get('/me', (UserController, #currentUser)),
Route.get('/<userId>', (UserController, #show)),
]),

/// Articles
Expand Down
4 changes: 2 additions & 2 deletions test/backend_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ void main() {
.test();
});

test('should return user for /users/<userId> ', () async {
test('should return user for /users/<userId> without auth', () async {
final randomUser = await DB.query<User>().get();
expect(randomUser, isA<User>());

await (await server.tester)
.get('$usersApiPath/${randomUser!.id!}', headers: {HttpHeaders.cookieHeader: authCookie!})
.get('$usersApiPath/${randomUser!.id!}')
.expectStatus(HttpStatus.ok)
.expectHeader(HttpHeaders.contentTypeHeader, 'application/json; charset=utf-8')
.expectBodyCustom((body) => jsonDecode(body)['user'], randomUser.toPublic)
Expand Down

0 comments on commit 343cfa3

Please sign in to comment.