1
0
Fork 0
freesewing/sites/backend/tests/user.all.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

201 lines
6.3 KiB
JavaScript

module.exports = function tests(store, config, chai) {
const email = Date.now() + config.user.email
describe(`Language-specific User controller signup routes`, () => {
for (let lang in config.languages) {
store[lang] = {
email: lang + email,
password: 'test'
}
it(config.languages[lang] + ' => should create a pending signup', done => {
chai
.request(config.backend)
.post('/signup')
.send({
email: store[lang].email,
password: store[lang].password,
language: lang
})
.end((err, res) => {
res.should.have.status(200)
res.text.should.equal('OK')
done()
})
})
it(config.languages[lang] + ' => should detect a pre-existing signup', done => {
chai
.request(config.backend)
.post('/signup')
.send({
email: store[lang].email,
password: store[lang].password,
language: lang
})
.end((err, res) => {
res.should.have.status(400)
res.text.should.equal('userExists')
done()
})
})
}
})
describe(`Send out emails for other tests that rely on email delivery`, () => {
it('should fetch the JWT token for test_user', done => {
chai
.request(config.backend)
.post('/login')
.send({
username: config.user.username,
password: config.user.password
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
store.emailChange = { token: data.token }
done()
})
})
it('should trigger the email change confirmation email', done => {
chai
.request(config.backend)
.put('/account')
.set('Authorization', 'Bearer ' + store.emailChange.token)
.send({
email: config.user.changedEmail
})
.end((err, res) => {
res.should.have.status(200)
done()
})
})
})
describe(`Take a ${config.sleep} second power nap while we wait for the emails to be delivered`, () => {
it(`should sleep for ${config.sleep} seconds to allow the emails to arrive`, done => {
console.log('\n 😴 \n')
setTimeout(() => {
done()
}, config.sleep * 1000)
}).timeout(config.sleep * 1010)
for (let lang in config.languages) {
it(
config.languages[lang] + ' => should have sent out an email to the signup email address',
done => {
let url = `/api/v2/search?kind=to&query=${lang}${email}`
chai
.request(config.mailhog)
.get(url)
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.total.should.equal(1)
let message = data.items[0]
message.From.Mailbox.should.equal('info')
message.From.Domain.should.equal('freesewing.org')
message.Content.Headers.Subject[0].should.equal(
config.strings[lang]['email.signupSubject']
)
store[lang].confirmation = message.Content.Headers[
'X-Freesewing-Confirmation-ID'
].pop()
done()
})
}
)
it(
config.languages[lang] +
' => should not activate the pending confirmation without consent',
done => {
chai
.request(config.backend)
.post('/account')
.send({
id: store[lang].confirmation
})
.end((err, res) => {
res.should.have.status(400)
res.text.should.equal('consentRequired')
done()
})
}
)
it(config.languages[lang] + ' => should activate the pending confirmation', done => {
chai
.request(config.backend)
.post('/account')
.send({
id: store[lang].confirmation,
consent: {
profile: true
}
})
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
data.account.settings.language.should.equal(lang)
data.account.settings.units.should.equal('metric')
data.account.handle.should.be.a('string')
data.account.role.should.equal('user')
data.account.patron.should.equal(0)
data.account.bio.should.equal('')
data.account.username.should.equal('user-' + data.account.handle)
data.account.__v.should.equal(0)
data.account.email.should.equal(lang + email)
data.account.pictureUris.xs
.split('/')
.pop()
.should.equal(data.account.handle + '.svg')
data.token.should.be.a('string')
store[lang].token = data.token
store[lang].username = data.account.username
store[lang].handle = data.account.handle
done()
})
})
}
it('should have sent out an email to confirm the email change', done => {
chai
.request(config.mailhog)
.get(`/api/v2/search?kind=to&query=${config.user.changedEmail}`)
.end((err, res) => {
res.should.have.status(200)
let data = JSON.parse(res.text)
let message = data.items[0]
message.From.Mailbox.should.equal('info')
message.From.Domain.should.equal('freesewing.org')
config.user.confirmation = message.Content.Headers['X-Freesewing-Confirmation-ID'].pop()
done()
})
})
})
/*
describe(`Other tests that depend on emails we sent out`, () => {
it('should update the confirmed account email address', (done) => {
chai.request(config.backend)
.post('/confirm/changed/email')
.set('Authorization', 'Bearer '+store.emailChange.token)
.send({
id: config.user.confirmation,
})
.end((err, res) => {
let data = JSON.parse(res.text);
res.should.have.status(200);
res.data.account.email.should.equal(config.user.changedEmail);
done();
});
})
});
*/
}