• Benjamin Zerbib 12
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi guys!

I created a trigger and a test class that successfully passed the tests, but when I try to run a test myself, nothing is happening...

Here is my trigger:
public class UserProfilePhotoPublicLink {
    public static void updateUserCustomURL(List<User> users) {
        for (User user : users) {
            if (user.SmallPhotoUrl != null && user.Custom_Photo_URL__c == null) {
                user.Custom_Photo_URL__c = user.SmallPhotoUrl.replace('caesarstone', 'BENJI');
            }
        }
        update users;
    }
}

And here is the test class:
@isTest
private class UserProfilePhotoPublicLinkTest {
    static User testUser;

    static testMethod void setUp() {
        // Create a test user
        testUser = new User(
            FirstName = 'Test',
            LastName = 'User',
            Email = 'testuser@example.com'
        );
        insert testUser;

        // Update the test user's SmallPhotoUrl
        //testUser.SmallPhotoUrl = 'https://example.com/s96-c/photo.jpg';
       // update testUser;
    }

    static testMethod void testUpdateUserCustomURL() {
        // Call the method being tested
        UserProfilePhotoPublicLink.updateUserCustomURL(new List<User> { testUser });

        // Verify that the Custom_Photo_URL__c field has been updated
        testUser = [SELECT Custom_Photo_URL__c FROM User WHERE Id = :testUser.Id];
        System.assertEquals(testUser.Custom_Photo_URL__c, 'https://example.com/photo.jpg');
    }
}

Somehow when I upload a new picture to a user (and then the SmallPhotoUrl is getting automatically populated), nothing is happening ​​in the Custom_Photo_URL__c.

I don't understand why because it should trigger the apex class.

Could you please help me?

Thanks a lot!
Benji