2024-10-15 04:15:43 -04:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import mongodb from 'mongodb-legacy'
|
|
|
|
import User from '../../../../../test/acceptance/src/helpers/User.js'
|
|
|
|
import MockProjectHistoryApiClass from '../../../../../test/acceptance/src/mocks/MockProjectHistoryApi.js'
|
2023-08-31 03:54:08 -04:00
|
|
|
|
2024-10-15 04:15:43 -04:00
|
|
|
const { ObjectId } = mongodb
|
2023-08-31 03:54:08 -04:00
|
|
|
|
|
|
|
let MockProjectHistoryApi
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
MockProjectHistoryApi = MockProjectHistoryApiClass.instance()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Labels', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
this.owner = new User()
|
2024-10-15 04:15:43 -04:00
|
|
|
this.owner.login(error => {
|
|
|
|
if (error) {
|
2023-08-31 03:54:08 -04:00
|
|
|
throw error
|
|
|
|
}
|
2024-10-15 04:15:43 -04:00
|
|
|
this.owner.createProject(
|
2023-08-31 03:54:08 -04:00
|
|
|
'example-project',
|
|
|
|
{ template: 'example' },
|
|
|
|
(error, projectId) => {
|
|
|
|
this.project_id = projectId
|
2024-10-15 04:15:43 -04:00
|
|
|
if (error) {
|
2023-08-31 03:54:08 -04:00
|
|
|
throw error
|
|
|
|
}
|
2024-10-15 04:15:43 -04:00
|
|
|
done()
|
2023-08-31 03:54:08 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('getting labels', function (done) {
|
|
|
|
const labelId = new ObjectId().toString()
|
|
|
|
const comment = 'a label comment'
|
|
|
|
const version = 3
|
|
|
|
MockProjectHistoryApi.addLabel(this.project_id, {
|
|
|
|
id: labelId,
|
|
|
|
comment,
|
|
|
|
version,
|
|
|
|
})
|
|
|
|
|
2024-10-15 04:15:43 -04:00
|
|
|
this.owner.request(
|
2023-08-31 03:54:08 -04:00
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
url: `/project/${this.project_id}/labels`,
|
|
|
|
json: true,
|
|
|
|
},
|
|
|
|
(error, response, body) => {
|
2024-10-15 04:15:43 -04:00
|
|
|
if (error) {
|
2023-08-31 03:54:08 -04:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
expect(body).to.deep.equal([{ id: labelId, comment, version }])
|
2024-10-15 04:15:43 -04:00
|
|
|
done()
|
2023-08-31 03:54:08 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('creating a label', function (done) {
|
|
|
|
const comment = 'a label comment'
|
|
|
|
const version = 3
|
|
|
|
|
2024-10-15 04:15:43 -04:00
|
|
|
this.owner.request(
|
2023-08-31 03:54:08 -04:00
|
|
|
{
|
|
|
|
method: 'POST',
|
|
|
|
url: `/project/${this.project_id}/labels`,
|
|
|
|
json: { comment, version },
|
|
|
|
},
|
|
|
|
(error, response, body) => {
|
2024-10-15 04:15:43 -04:00
|
|
|
if (error) {
|
2023-08-31 03:54:08 -04:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
const { label_id: labelId } = body
|
|
|
|
expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal([
|
|
|
|
{ id: labelId, comment, version },
|
|
|
|
])
|
2024-10-15 04:15:43 -04:00
|
|
|
done()
|
2023-08-31 03:54:08 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('deleting a label', function (done) {
|
|
|
|
const labelId = new ObjectId().toString()
|
|
|
|
const comment = 'a label comment'
|
|
|
|
const version = 3
|
|
|
|
MockProjectHistoryApi.addLabel(this.project_id, {
|
|
|
|
id: labelId,
|
|
|
|
comment,
|
|
|
|
version,
|
|
|
|
})
|
|
|
|
|
2024-10-15 04:15:43 -04:00
|
|
|
this.owner.request(
|
2023-08-31 03:54:08 -04:00
|
|
|
{
|
|
|
|
method: 'DELETE',
|
|
|
|
url: `/project/${this.project_id}/labels/${labelId}`,
|
|
|
|
json: true,
|
|
|
|
},
|
|
|
|
(error, response, body) => {
|
2024-10-15 04:15:43 -04:00
|
|
|
if (error) {
|
2023-08-31 03:54:08 -04:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
expect(response.statusCode).to.equal(204)
|
|
|
|
expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal(
|
|
|
|
[]
|
|
|
|
)
|
2024-10-15 04:15:43 -04:00
|
|
|
done()
|
2023-08-31 03:54:08 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|