{%- import "cloudevents.jinja.include" as cloudEvents -%}
{%- import "util.jinja.include" as util -%}
// This code was generated by the xRegistry tool.
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.

import { EventHubProducerClient } from '@azure/event-hubs';
{%- set messagegroups = root.messagegroups %}
{%- set uses_cloudevents_message = cloudEvents.usesCloudEvents(root) %}

import { {% for messagegroupid, messagegroup in messagegroups.items() -%}{%- set class_name = (messagegroupid | pascal | strip_namespace) + "Producer" %}{{ class_name }}{% if not loop.last %}, {% endif %}{% endfor %} } from '../src';
{%- if uses_cloudevents_message %}
import { CloudEvent } from 'cloudevents';
{%- endif %}

// Import data types (need to compile data project first: cd ../{{ data_project_name }} && npm install && npm run build)
// NOTE: In real usage, the data project should be a proper npm package dependency
import * as {{ data_project_name }} from '../../{{ data_project_name }}/dist/index.js';

const EVENT_HUB_CONNECTION_STRING = process.env.EVENT_HUB_CONNECTION_STRING || 
    'Endpoint=sb://testlocal;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=dGVzdGtleQ==;EntityPath=test-hub';
const EVENT_HUB_NAME = 'test-hub';

jest.setTimeout(10000);

{%- for messagegroupid, messagegroup in messagegroups.items() %}
{%- set pascal_group_name = messagegroupid | pascal %}
{%- set class_name = (pascal_group_name | strip_namespace) + "Producer" %}
{%- set test_class_name = (project_name | strip_dots | pascal) + (pascal_group_name | strip_dots) + "Tests" %}

describe('{{ test_class_name }}', () => {
    // Tests verify producer instantiation and basic send operations
    // For full integration testing with Event Hubs emulator, configure EVENT_HUB_CONNECTION_STRING environment variable

    {%- set message_list = messagegroup.messages.items() | list %}
    {%- for messageid, message in message_list[:3] %}
    {%- set messagename = messageid | strip_namespace | pascal %}
    {%- set body_type = util.body_type(data_project_name, root, message) %}
    
    test('should instantiate {{ messagename }} producer', async () => {
        const producerClient = new EventHubProducerClient(EVENT_HUB_CONNECTION_STRING);
        const producer = new {{ class_name }}(producerClient);
        
        // Verify producer can be instantiated
        expect(producer).toBeDefined();
        expect(producer.send{{ messagename }}). toBeDefined();
        expect(producer.send{{ messagename }}Batch).toBeDefined();
        
        await producer.close();
    });
    {%- endfor %}
});
{%- endfor %}
