All Downloads are FREE. Search and download functionalities are using the official Maven repository.

C-libcurl.api_user_test.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
#include 
    #include 
    #include 
    #include 
    #include "apiClient.h"
    #include "cJSON.h"
    #include "keyValuePair.h"
    #include "user.h"
    #include "UserAPI.h"

    #define USER_ID 1234
    #define USER_NAME "example123"
    #define FIRST_NAME "Example1"
    #define LAST_NAME "Example2Last"
    #define LAST_NAME1 "LastName"
    #define EMAIL "[email protected]"
    #define PASSWORD "thisisexample!123"
    #define PHONE "+123456789"
    #define USER_STATUS 4


int main() {
//create user test
	apiClient_t *apiClient = apiClient_create();

	char *username = malloc(strlen(USER_NAME) + 1);
	strcpy(username, USER_NAME);
	char *firstname = malloc(strlen(FIRST_NAME) + 1);
	strcpy(firstname, FIRST_NAME);
	char *lastname = malloc(strlen(LAST_NAME) + 1);
	strcpy(lastname, LAST_NAME);
	char *email = malloc(strlen(EMAIL) + 1);
	strcpy(email, EMAIL);
	char *password = malloc(strlen(PASSWORD) + 1);
	strcpy(password, PASSWORD);
	char *phone = malloc(strlen(PHONE) + 1);
	strcpy(phone, PHONE);

	user_t *newuser = user_create(USER_ID,
	                              username,
	                              firstname,
	                              lastname,
	                              email,
	                              password,
	                              phone,
	                              USER_STATUS);

	UserAPI_createUser(apiClient, newuser);
	user_free(newuser);

//get user by name test
	apiClient_t *apiClient1 = apiClient_create();
	user_t *returnUser = UserAPI_getUserByName(apiClient1, USER_NAME);

	cJSON *JSONNODE = user_convertToJSON(returnUser);

	char *dataToPrint = cJSON_Print(JSONNODE);

	printf("User is: \n%s\n", dataToPrint);
	user_free(returnUser);
	cJSON_Delete(JSONNODE);
	free(dataToPrint);

//update user test
	{
		apiClient_t *apiClient2 = apiClient_create();
		char *username1 = malloc(strlen(USER_NAME) + 1);
		strcpy(username1, USER_NAME);
		char *firstname = malloc(strlen(FIRST_NAME) + 1);
		strcpy(firstname, FIRST_NAME);
		char *lastname = malloc(strlen(LAST_NAME) + 1);
		strcpy(lastname, LAST_NAME);
		char *email = malloc(strlen(EMAIL) + 1);
		strcpy(email, EMAIL);
		char *password = malloc(strlen(PASSWORD) + 1);
		strcpy(password, PASSWORD);
		char *phone = malloc(strlen(PHONE) + 1);
		strcpy(phone, PHONE);

		user_t *newuser1 = user_create(USER_ID,
		                               username1,
		                               firstname,
		                               lastname,
		                               email,
		                               password,
		                               phone,
		                               USER_STATUS);

		UserAPI_updateUser(apiClient2, username1, newuser1);
		user_free(newuser1);
	}

//login user test
	{
		char *username1 = malloc(strlen(USER_NAME) + 1);
		strcpy(username1, USER_NAME);
		char *password = malloc(strlen(PASSWORD) + 1);
		strcpy(password, PASSWORD);
		apiClient_t *apiClient3 = apiClient_create();

		char *loginuserreturn = UserAPI_loginUser(apiClient3,
		                                          username1,
		                                          password);

		printf("Login User: %s\n", loginuserreturn);
		free(loginuserreturn);
		free(username1);
		free(password);
	}

// logout user test
 apiClient_t *apiClient4 = apiClient_create();

 UserAPI_logoutUser(apiClient4);


// delete user test
 apiClient_t *apiClient5 = apiClient_create();

 UserAPI_deleteUser(apiClient5, "example123");
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy