Skip to content

Commit

Permalink
Merge branch 'emqx-backend-update' into team-broker-client-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
hardillb authored Oct 15, 2024
2 parents 63d9ecc + b50a4e1 commit cbb199c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
38 changes: 29 additions & 9 deletions forge/ee/routes/teamBroker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ module.exports = async function (app) {

/**
* Get the Teams MQTT Clients
* @name /api/v1/team/:teamId/broker/users
* @name /api/v1/teams/:teamId/broker/clients
* @static
* @memberof forge.routes.api.team.broker
*/
app.get('/users', {
app.get('/clients', {
schema: {
summary: 'List MQTT users for the team',
summary: 'List MQTT clients for the team',
tags: ['MQTT Broker'],
query: { $ref: 'PaginationParams' },
params: {
Expand Down Expand Up @@ -73,9 +73,16 @@ module.exports = async function (app) {
reply.send(app.db.views.TeamBrokerClient.users(users))
})

app.post('/user', {
/**
* Creates a new MQTT Client
* @name /api/v1/teams/:teamId/broker/client
* @static
* @memberof forge.routes.api.team.broker
*/
app.post('/client', {
preHandler: app.needsPermission('project:create'),
schema: {
summary: 'Create new MQTT user for the team',
summary: 'Create new MQTT client for the team',
tags: ['MQTT Broker'],
params: {
type: 'object',
Expand Down Expand Up @@ -125,9 +132,15 @@ module.exports = async function (app) {
}
})

app.get('/user/:username', {
/**
* Get a specific MQTT Client
* @name /api/v1/teams/:teamId/broker/client/:username
* @static
* @memberof forge.routes.api.team.broker
*/
app.get('/client/:username', {
schema: {
summary: 'Get details about a specific MQTT User',
summary: 'Get details about a specific MQTT client',
tags: ['MQTT Broker'],
params: {
type: 'object',
Expand Down Expand Up @@ -162,9 +175,16 @@ module.exports = async function (app) {
}
})

app.delete('/user/:username', {
/**
* Delete a MQTT Clients
* @name /api/v1/teams/:teamId/broker/client/:username
* @static
* @memberof forge.routes.api.team.broker
*/
app.delete('/client/:username', {
preHandler: app.needsPermission('project:create'),
schema: {
summary: 'Delete a MQTT User',
summary: 'Delete a MQTT client',
tags: ['MQTT Broker'],
params: {
type: 'object',
Expand Down
24 changes: 12 additions & 12 deletions test/unit/forge/ee/routes/teamBroker/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Team Broker API', function () {
it('Create MQTT Broker User', async function () {
const response = await app.inject({
method: 'POST',
url: `/api/v1/teams/${app.team.hashid}/broker/user`,
url: `/api/v1/teams/${app.team.hashid}/broker/client`,
cookies: { sid: TestObjects.tokens.alice },
body: {
username: 'alice',
Expand All @@ -79,7 +79,7 @@ describe('Team Broker API', function () {
it('Get all MQTT broker users for a team', async function () {
const response = await app.inject({
method: 'GET',
url: `/api/v1/teams/${app.team.hashid}/broker/users`,
url: `/api/v1/teams/${app.team.hashid}/broker/clients`,
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(200)
Expand All @@ -91,7 +91,7 @@ describe('Team Broker API', function () {
it('Get specific MQTT broker user for a team', async function () {
const response = await app.inject({
method: 'GET',
url: `/api/v1/teams/${app.team.hashid}/broker/user/alice`,
url: `/api/v1/teams/${app.team.hashid}/broker/client/alice`,
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(200)
Expand All @@ -102,7 +102,7 @@ describe('Team Broker API', function () {
it('Get specific MQTT broker user for a team who doesn\'t exist', async function () {
const response = await app.inject({
method: 'GET',
url: `/api/v1/teams/${app.team.hashid}/broker/user/bob`,
url: `/api/v1/teams/${app.team.hashid}/broker/client/bob`,
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(404)
Expand All @@ -111,7 +111,7 @@ describe('Team Broker API', function () {
it('Limit number of MQTT broker users allowed', async function () {
let response = await app.inject({
method: 'GET',
url: `/api/v1/teams/${app.team.hashid}/broker/users`,
url: `/api/v1/teams/${app.team.hashid}/broker/clients`,
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(200)
Expand All @@ -121,7 +121,7 @@ describe('Team Broker API', function () {
for (let i = start; i < MAX_BROKER_USERS; i++) {
const create = await app.inject({
method: 'POST',
url: `/api/v1/teams/${app.team.hashid}/broker/user`,
url: `/api/v1/teams/${app.team.hashid}/broker/client`,
cookies: { sid: TestObjects.tokens.alice },
body: {
username: `alice-${i}`,
Expand All @@ -138,15 +138,15 @@ describe('Team Broker API', function () {
}
response = await app.inject({
method: 'GET',
url: `/api/v1/teams/${app.team.hashid}/broker/users`,
url: `/api/v1/teams/${app.team.hashid}/broker/clients`,
cookies: { sid: TestObjects.tokens.alice }
})
result = response.json()
result.clients.should.have.a.lengthOf(MAX_BROKER_USERS)

response = await app.inject({
method: 'POST',
url: `/api/v1/teams/${app.team.hashid}/broker/user`,
url: `/api/v1/teams/${app.team.hashid}/broker/client`,
cookies: { sid: TestObjects.tokens.alice },
body: {
username: 'alice-5',
Expand All @@ -167,7 +167,7 @@ describe('Team Broker API', function () {
it('Delete MQTT Broker User', async function () {
const response = await app.inject({
method: 'DELETE',
url: `/api/v1/teams/${app.team.hashid}/broker/user/alice`,
url: `/api/v1/teams/${app.team.hashid}/broker/client/alice`,
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(200)
Expand All @@ -178,7 +178,7 @@ describe('Team Broker API', function () {
it('Delete MQTT Broker User who doesn\'t exist', async function () {
const response = await app.inject({
method: 'DELETE',
url: `/api/v1/teams/${app.team.hashid}/broker/user/bob`,
url: `/api/v1/teams/${app.team.hashid}/broker/client/bob`,
cookies: { sid: TestObjects.tokens.alice }
})
response.statusCode.should.equal(404)
Expand All @@ -188,7 +188,7 @@ describe('Team Broker API', function () {
before(async function () {
await app.inject({
method: 'POST',
url: `/api/v1/teams/${app.team.hashid}/broker/user`,
url: `/api/v1/teams/${app.team.hashid}/broker/client`,
cookies: { sid: TestObjects.tokens.alice },
body: {
username: 'alice',
Expand All @@ -205,7 +205,7 @@ describe('Team Broker API', function () {
after(async function () {
await app.inject({
method: 'DELETE',
url: `/api/v1/teams/${app.team.hashid}/broker/user/alice`,
url: `/api/v1/teams/${app.team.hashid}/broker/client/alice`,
cookies: { sid: TestObjects.tokens.alice }
})
})
Expand Down

0 comments on commit cbb199c

Please sign in to comment.