1
0
Fork 0
freesewing/sites/backend/tests/person.test.js
Joost De Cock e4035b2509 chore: Re-structure workspaces, enforce build order
These are some changes in the way the monorepo is structured,
that are aimed at making it easier to get started.

There are two important changes:

**Multiple workspaces**

We had a yarn workspaces setup at `packages/*`. But our monorepo has
grown to 92 packages which can be overwhelming for people not familiar
with the package names.

To remedy this, I've split it into 4 different workspaces:

- `designs/*`: Holds FreeSewing designs (think patterns)
- `plugins/*`: Holds FreeSewing plugins
- `packages/*`: Holds other packages published on NPM
- `sites/*`: Holds software that is not published as an NPM package,
  such as our various websites and backend API

This should make it easier to find things, and to answer questions like
*where do I find the code for the plugins*.

**Updated reconfigure script to handle build order**

One problem when bootstrapping the repo is inter-dependencies between
packages. For example, building a pattern will only work once
`plugin-bundle` is built. Which will only work once all plugins in the
bundle or built. And that will only work when `core` is built, and so
on.

This can be frustrating for new users as `yarn buildall` will fail.
And it gets overlooked by seasoned devs because they're likely to have
every package built in their repo so this issue doesn't concern them.

To remedy this, we now have a `config/build-order.mjs` file and the
updated `/scripts/reconfigure.mjs` script will enforce the build order
so that things *just work*.
2022-06-16 17:11:31 +02:00

195 lines
6 KiB
JavaScript

module.exports = function tests(store, config, chai) {
const should = chai.should()
describe('Person endpoints', () => {
it('should create a person', done => {
chai
.request(config.backend)
.post('/people')
.set('Authorization', 'Bearer ' + config.user.token)
.send({
name: 'Test person',
units: 'imperial',
breasts: true
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.breasts.should.be.true
data.person.units.should.equal('imperial')
data.person.name.should.equal('Test person')
data.person.pictureUris.xs
.split('/')
.pop()
.should.equal(data.person.handle + '.svg')
config.user.person = data.person.handle
done()
})
})
it('should update the person name', done => {
chai
.request(config.backend)
.put('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.send({
name: 'New person name'
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.name.should.equal('New person name')
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should update the person chest', done => {
chai
.request(config.backend)
.put('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.send({
breasts: 'false'
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.breasts.should.be.false
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should update the person units', done => {
chai
.request(config.backend)
.put('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.send({
units: 'metric'
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.units.should.equal('metric')
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should update the person notes', done => {
chai
.request(config.backend)
.put('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.send({
notes: 'These are the notes'
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.notes.should.equal('These are the notes')
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should update the person measurements', done => {
chai
.request(config.backend)
.put('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.send({
measurements: {
shoulderToShoulder: 456,
neck: 345
}
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.measurements.shoulderToShoulder.should.equal(456)
data.person.measurements.neck.should.equal(345)
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should not set a non-existing measurement', done => {
chai
.request(config.backend)
.put('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.send({
measurements: {
hairLength: 12
}
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
should.not.exist(data.person.measurements.hairLength)
data.person.measurements.shoulderToShoulder.should.equal(456)
data.person.measurements.neck.should.equal(345)
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should update the person avatar', done => {
chai
.request(config.backend)
.put('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.send({
picture: config.avatar
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.measurements.shoulderToShoulder.should.equal(456)
data.person.measurements.neck.should.equal(345)
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should load the person data', done => {
chai
.request(config.backend)
.get('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.person.measurements.shoulderToShoulder.should.equal(456)
data.person.measurements.neck.should.equal(345)
data.person.handle.should.equal(config.user.person)
done()
})
})
it('should delete the person', done => {
chai
.request(config.backend)
.delete('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.end((err, res) => {
res.should.have.status(204)
done()
})
})
it('should no longer have this person', done => {
chai
.request(config.backend)
.get('/people/' + config.user.person)
.set('Authorization', 'Bearer ' + config.user.token)
.end((err, res) => {
res.should.have.status(404)
done()
})
})
})
}