Skip to content

Commit 8df148c

Browse files
Merge pull request #701 from freeCodeCamp/main
Create a new pull request by comparing changes across two branches
2 parents 13f666b + b7feb4e commit 8df148c

File tree

68 files changed

+787
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+787
-547
lines changed

api-server/src/server/boot/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function updateMyProfileUI(req, res, next) {
170170
);
171171
}
172172

173-
function updateMyAbout(req, res, next) {
173+
export function updateMyAbout(req, res, next) {
174174
const {
175175
user,
176176
body: { name, location, about, picture }

api-server/src/server/boot_tests/settings.test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { updateMySocials, updateMyClassroomMode } from '../boot/settings';
1+
import {
2+
updateMyAbout,
3+
updateMySocials,
4+
updateMyClassroomMode
5+
} from '../boot/settings';
26

37
export const mockReq = opts => {
48
const req = {};
@@ -17,6 +21,36 @@ export const mockRes = opts => {
1721
};
1822

1923
describe('boot/settings', () => {
24+
describe('updateMyAbout', () => {
25+
it('allows empty string in any field', () => {
26+
let updateData;
27+
const req = mockReq({
28+
user: {
29+
updateAttributes: (update, cb) => {
30+
updateData = update;
31+
cb();
32+
}
33+
},
34+
body: {
35+
name: '',
36+
location: '',
37+
about: '',
38+
picture: ''
39+
}
40+
});
41+
const res = mockRes();
42+
const next = jest.fn();
43+
updateMyAbout(req, res, next);
44+
expect(res.status).toHaveBeenCalledWith(200);
45+
expect(updateData).toStrictEqual({
46+
name: '',
47+
location: '',
48+
about: '',
49+
picture: ''
50+
});
51+
});
52+
});
53+
2054
describe('updateMySocials', () => {
2155
it('does not allow non-github domain in GitHub social', () => {
2256
const req = mockReq({

api/src/routes/settings.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,43 @@ Happy coding!
922922
});
923923
expect(response.statusCode).toEqual(200);
924924
});
925+
926+
test('PUT with empty strings clears the values in about settings ', async () => {
927+
const initialResponse = await superPut('/update-my-about').send({
928+
about: 'Teacher at freeCodeCamp',
929+
name: 'Quincy Larson',
930+
location: 'USA',
931+
picture:
932+
'https://cdn.freecodecamp.org/platform/english/images/quincy-larson-signature.svg'
933+
});
934+
935+
expect(initialResponse.body).toEqual({
936+
message: 'flash.updated-about-me',
937+
type: 'success'
938+
});
939+
expect(initialResponse.statusCode).toEqual(200);
940+
941+
const response = await superPut('/update-my-about').send({
942+
about: '',
943+
name: '',
944+
location: '',
945+
picture: ''
946+
});
947+
948+
expect(response.body).toEqual({
949+
message: 'flash.updated-about-me',
950+
type: 'success'
951+
});
952+
expect(response.statusCode).toEqual(200);
953+
954+
const user = await fastifyTestInstance?.prisma.user.findFirst({
955+
where: { email: '[email protected]' }
956+
});
957+
expect(user?.about).toEqual('');
958+
expect(user?.name).toEqual('');
959+
expect(user?.location).toEqual('');
960+
expect(user?.picture).toEqual('');
961+
});
925962
});
926963

927964
describe('/update-my-honesty', () => {

0 commit comments

Comments
 (0)