Skip to content

Commit

Permalink
Admin endpoin for UI in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
sdg9 committed Apr 12, 2022
1 parent a759a44 commit 691fff7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
54 changes: 54 additions & 0 deletions libs/core/src/lib/__tests__/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,58 @@ describe('mezzo', () => {
expect(res.text).toBe('TODO HTML Site');
});
});

describe('/mezzo/routes', () => {
it.only('should return all routes for admin GUI', async () => {
mezzo
.route({
id: 'GET /route1',
path: 'route1',
handler: function (req, res) {
res.json({ someKey: 'A' });
},
})
.variant({
id: 'variant1',
handler: function (req, res) {
res.json({ someKey: 'B' });
},
});
mezzo.route({
id: 'POST /route2',
path: 'route2',
method: 'POST',
handler: function (req, res) {
res.json({ someKey: 'C' });
},
});
await mezzo.setMockVariant({
routeId: 'GET /route1',
variantId: 'variant1',
});

const res = await request.get('/mezzo/routes');
expect(res.status).toBe(200);
expect(res.body).toEqual([
{
_activeVariant: 'variant1',
_variants: {},
id: 'GET /route1',
method: 'GET',
path: 'route1',
routeData: { id: 'GET /route1', path: 'route1' },
sessionState: { state: {} },
},
{
_activeVariant: 'default',
_variants: {},
id: 'POST /route2',
method: 'POST',
path: 'route2',
routeData: { id: 'POST /route2', method: 'POST', path: 'route2' },
sessionState: { state: {} },
},
]);
});
});
});
12 changes: 12 additions & 0 deletions libs/core/src/lib/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ export const addAdminEndpoints = (app: express.Express, mezzo: Mezzo) => {
});
});

app.get(`/mezzo/routes`, (req, res) => {
// const routes = mezzo.userRoutes;
// TODO: format and return data
res.json(mezzo.userRoutes);
// res.json({
// id: 'todoId',
// routes: 'todoRoutes',
// profiles: 'todoProfiles',
// actions: 'todoActions',
// });
});

// setMockVariahttps://github.com/sgoff0/midway/blob/6614a6a91d3060951e99326c68333ebf78563e8c/src/utils/common-utils.ts#L318-L356nt
app.post(`${MEZZO_API_PATH}/route/:id`, (req, res) => {
const routeId = req.params.id;
Expand Down

0 comments on commit 691fff7

Please sign in to comment.