package com.orchard.models;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.connect.data.Struct;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;


public class GSSocialAccountIdsTests {
    GSSocialAccountIds socialAccountIds = new GSSocialAccountIds();
    public static final String socialAccountIdsJson =
      "{\"spotify\":[\"testspotifyid\"],\"appleMusic\":[\"testapplemusicid\"]}";

    public GSSocialAccountIdsTests() {
        socialAccountIds.spotify = new ArrayList<String>();
        socialAccountIds.spotify.add("testspotifyid");
        socialAccountIds.appleMusic = new ArrayList<String>();
        socialAccountIds.appleMusic.add("testapplemusicid");
    }

    @Test
    public void shouldReturnValidKafkaStruct() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        GSSocialAccountIds socialAccountIdsParsed = mapper.readValue(socialAccountIdsJson, GSSocialAccountIds.class);
        Struct kafkaStruct = socialAccountIds.ToKafkaStruct();
        List<String> spotify = kafkaStruct.getArray("spotify");
        assertArrayEquals(
                socialAccountIdsParsed.spotify.toArray(), 
                spotify.toArray());
        List<String> appleMusic = kafkaStruct.getArray("appleMusic");
        assertArrayEquals(
                socialAccountIdsParsed.appleMusic.toArray(), 
                appleMusic.toArray());
    }
}
