profile: store preferred language in the database

This commit is contained in:
Girish Ramakrishnan
2024-02-26 12:32:14 +01:00
parent 6d6107161e
commit 6525504923
10 changed files with 150 additions and 14 deletions

View File

@@ -56,6 +56,7 @@ describe('Profile API', function () {
expect(response.body.displayName).to.be.a('string');
expect(response.body.password).to.not.be.ok();
expect(response.body.salt).to.not.be.ok();
expect(response.body.language).to.be('');
});
it('fails with expired token', async function () {
@@ -370,4 +371,54 @@ describe('Profile API', function () {
expect(response.body).to.eql(defaultAvatar);
});
});
describe('language', function () {
it('fails to set unknown language', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/profile/language`)
.query({ access_token: user.token })
.send({ language: 'ta' })
.ok(() => true);
expect(response.statusCode).to.be(400);
});
it('fails to set bad language', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/profile/language`)
.query({ access_token: user.token })
.send({ language: 123 })
.ok(() => true);
expect(response.statusCode).to.be(400);
});
it('fails to set unknown language', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/profile/language`)
.query({ access_token: user.token })
.send({ language: 'ta' })
.ok(() => true);
expect(response.statusCode).to.be(400);
});
it('set valid language', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/profile/language`)
.query({ access_token: user.token })
.send({ language: 'en' });
expect(response.statusCode).to.be(204);
});
it('did set language', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/profile`).query({ access_token: user.token });
expect(response.body.language).to.contain('en');
});
it('reset valid language', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/profile/language`)
.query({ access_token: user.token })
.send({ language: '' });
expect(response.statusCode).to.be(204);
});
it('did reset language', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/profile`).query({ access_token: user.token });
expect(response.body.language).to.contain('');
});
});
});