Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/settings.test.ts (TypeScript)

Code before:
        expect(user?.picture).toEqual(
          'https://cdn.freecodecamp.org/platform/english/images/quincy-larson-signature.svg'
        );
        expect(response.statusCode).toEqual(200);
      });

      test('PUT updates the values in about settings without image', async () => {
        const response = await superRequest('/update-my-about', {
          method: 'PUT',
          setCookies
        }).send({
          about: 'Teacher at freeCodeCamp',
          name: 'Quincy Larson',
          location: 'USA',
          // `new URL` throws if the image isn't a URL, this checks if it doesn't throw.
          picture: ''
        });

        expect(response.body).toEqual({
          message: 'flash.updated-about-me',
          type: 'success'
        });
        expect(response.statusCode).toEqual(200);
      });

      test('PUT throw 500 if the image is invalid', async () => {
        const response = await superRequest('/update-my-about', {
          method: 'PUT',
          setCookies
        }).send({
          about: 'Teacher at freeCodeCamp',
          name: 'Quincy Larson',
          location: 'USA',
          picture: 'invaild'
        });

        expect(response.body).toEqual({
          message:
            'Failed to serialize an error. Error: "type" is required!. Original error: cb is not a function',
          code: 'FST_ERR_FAILED_ERROR_SERIALIZATION',
          statusCode: 500
        });
      });
    });

    describe('/update-my-honesty', () => {
      test('PUT returns 200 status code with "success" message', async () => {
        const response = await superRequest('/update-my-honesty', {
          method: 'PUT',
          setCookies
        }).send({ isHonest: true });

Review comment (suggestion):
```suggestion
      test('PUT should ignore invalid picture urls', async () => {
```

Code after:
            acceptedPrivacyTerms: true,
            emailVerified: true,
            externalId: 'externalId',
            isDonating: true,
            picture: 'picture',
            sendQuincyEmail: true,
            unsubscribeId: 'unsubscribeId'
          }
        });
        await superRequest('/update-my-username', {
          method: 'PUT',
          setCookies
        }).send({
          username: 'twaha2'
        });

        const secondUpdate = await superRequest('/update-my-username', {
          method: 'PUT',
          setCookies
        }).send({
          username: 'twaha2'
        });

        expect(secondUpdate.body).toEqual({
          message: 'flash.username-used',
          type: 'info'
        });
        expect(secondUpdate.statusCode).toEqual(400);

        // Not allowed because, while the usernameDisplay is different, the
        // username is not
        const existingUser = await superRequest('/update-my-username', {
          method: 'PUT',
          setCookies
        }).send({
          username: 'SemBauke'
        });

        expect(existingUser.body).toEqual({
          message: 'flash.username-taken',
          type: 'info'
        });
        expect(existingUser.statusCode).toEqual(400);
      });

      test('PUT returns 200 status code with "success" message', async () => {
        await superRequest('/update-my-username', {
          method: 'PUT',
          setCookies
        }).send({
          username: 'twaha3'