Skip to content

Commit 523dce9

Browse files
committed
refactor: First pass of logging on version_router
1 parent b1ff077 commit 523dce9

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

core/database/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if( ENABLE_FOXX_TESTS )
2828
add_test(NAME foxx_version COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_version:")
2929
add_test(NAME foxx_support COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_support:")
3030
add_test(NAME foxx_user_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_user_router:")
31+
add_test(NAME foxx_version_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_version_router:")
3132
add_test(NAME foxx_task_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_task_router:")
3233
add_test(NAME foxx_authz_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_authz_router:")
3334
add_test(NAME foxx_query_router COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_foxx.sh" -t "unit_query_router:")
@@ -53,6 +54,7 @@ if( ENABLE_FOXX_TESTS )
5354
set_tests_properties(foxx_validation_repo PROPERTIES FIXTURES_REQUIRED Foxx)
5455
set_tests_properties(foxx_path PROPERTIES FIXTURES_REQUIRED Foxx)
5556
set_tests_properties(foxx_user_router PROPERTIES FIXTURES_REQUIRED "Foxx;FoxxDBFixtures")
57+
set_tests_properties(foxx_version_router PROPERTIES FIXTURES_REQUIRED Foxx)
5658
set_tests_properties(foxx_query_router PROPERTIES FIXTURES_REQUIRED Foxx)
5759
set_tests_properties(foxx_task_router PROPERTIES FIXTURES_REQUIRED Foxx)
5860
set_tests_properties(foxx_unit_user_token PROPERTIES FIXTURES_REQUIRED Foxx)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
const createRouter = require('@arangodb/foxx/router');
4+
const router = createRouter();
5+
const joi = require('joi');
6+
const g_db = require('@arangodb').db;
7+
const g_lib = require('./support');
8+
const logger = require("./lib/logger");
9+
const basePath = "";
10+
11+
module.exports = router;
12+
13+
14+
//==================== ACL API FUNCTIONS
15+
16+
17+
router.get('/version', function(req, res) {
18+
let client = null;
19+
try {
20+
client = req.queryParams.client;
21+
logger.logRequestStarted({
22+
client: client,
23+
correlationId: req.headers["x-correlation-id"],
24+
httpVerb: "GET",
25+
routePath: basePath + "/version",
26+
status: "Started",
27+
description: "Get version numbers",
28+
});
29+
res.send({
30+
"release_year": 2025,
31+
"release_month": 10,
32+
"release_day": 7,
33+
"release_hour": 14,
34+
"release_minute": 1,
35+
"api_major": 1,
36+
"api_minor": 1,
37+
"api_patch": 0,
38+
"component_major": 1,
39+
"component_minor": 1,
40+
"component_patch": 0
41+
});
42+
logger.logRequestSuccess({
43+
client: client,
44+
correlationId: req.headers["x-correlation-id"],
45+
httpVerb: "GET",
46+
routePath: basePath + "/version",
47+
status: "Success",
48+
description: "Get version numbers",
49+
extra: null
50+
});
51+
} catch (e) {
52+
logger.logRequestFailure({
53+
client: client,
54+
correlationId: req.headers["x-correlation-id"],
55+
httpVerb: "GET",
56+
routePath: basePath + "/version",
57+
status: "Failure",
58+
description: "Get version numbers",
59+
extra: null,
60+
error: e
61+
});
62+
g_lib.handleException(e, res);
63+
}
64+
})
65+
.summary('Get version numbers')
66+
.description('Get version number of Foxx service, of foxx API and of release');
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
3+
const { expect } = require("chai");
4+
const request = require("@arangodb/request");
5+
const { baseUrl } = module.context;
6+
const { db } = require("@arangodb");
7+
8+
// (replace “myrouter” with the actual base path)
9+
const base_url = `${baseUrl}/`;
10+
11+
after(function () {
12+
// cleanup collections if needed
13+
const collections = [ /* list collections to truncate */ ];
14+
collections.forEach(name => {
15+
let col = db._collection(name);
16+
if (col) col.truncate();
17+
});
18+
});
19+
20+
describe("unit_version_router: the Foxx microservice version/ endpoint", () => {
21+
beforeEach(() => {
22+
// ensure collections exist & trimmed/initialized
23+
const collections = [ /* list collections */ ];
24+
collections.forEach(name => {
25+
let col = db._collection(name);
26+
if (col) {
27+
col.truncate();
28+
} else {
29+
db._create(name);
30+
}
31+
});
32+
});
33+
34+
it("should succeed when valid parameters given", () => {
35+
// arrange: setup fixture data
36+
// e.g., db.u.save({...}); db.mycoll.save({...});
37+
// TODO: insert required documents
38+
39+
// arrange: build request string
40+
const request_string = `${base_url}/version`;
41+
42+
// act
43+
const response = request.get(request_string);
44+
45+
// assert
46+
expect(response.status).to.equal(200);
47+
// additional assertions on response body (if needed)
48+
});
49+
});

0 commit comments

Comments
 (0)