github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/tequilapi/contract/node_test.go (about)

     1  /*
     2   * Copyright (C) 2022 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package contract
    19  
    20  import (
    21  	"fmt"
    22  	"testing"
    23  	"time"
    24  
    25  	"github.com/mysteriumnetwork/node/core/node"
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  func TestProviderSession(t *testing.T) {
    30  	for _, data := range []struct {
    31  		from     node.SessionItem
    32  		expected ProviderSession
    33  	}{
    34  		{
    35  			from: node.SessionItem{
    36  				ID:              "ID",
    37  				ConsumerCountry: "US",
    38  				ServiceType:     "wireguard",
    39  				Duration:        145,
    40  				StartedAt:       1659956756,
    41  				Earning:         "1.23456789",
    42  				Transferred:     123456789,
    43  			},
    44  			expected: ProviderSession{
    45  				ID:               "ID",
    46  				ConsumerCountry:  "US",
    47  				ServiceType:      "wireguard",
    48  				DurationSeconds:  145,
    49  				StartedAt:        time.Unix(1659956756, 0).Format(time.RFC3339),
    50  				TransferredBytes: 123456789,
    51  			},
    52  		},
    53  	} {
    54  		t.Run(fmt.Sprintf("%+v", data), func(t *testing.T) {
    55  			items := []node.SessionItem{data.from}
    56  			actual := NewProviderSessionsResponse(items).Sessions[0]
    57  			assert.Equal(t, data.expected.ID, actual.ID)
    58  			assert.Equal(t, data.expected.ConsumerCountry, actual.ConsumerCountry)
    59  			assert.Equal(t, data.expected.ServiceType, actual.ServiceType)
    60  			assert.Equal(t, data.expected.DurationSeconds, actual.DurationSeconds)
    61  			assert.Equal(t, data.expected.StartedAt, actual.StartedAt)
    62  			assert.Equal(t, data.expected.TransferredBytes, actual.TransferredBytes)
    63  		})
    64  	}
    65  
    66  }