github.com/uvalib/orcid-access-ws@v0.0.0-20250612130209-7d062dbabf9d/orcidaccessws/tests/set_attribs_test.go (about)

     1  package test
     2  
     3  import (
     4  	"net/http"
     5  	//"github.com/uvalib/orcid-access-ws/orcidaccessws/api"
     6  	"github.com/uvalib/orcid-access-ws/orcidaccessws/client"
     7  	"testing"
     8  )
     9  
    10  //
    11  // set ORCID attributes tests
    12  //
    13  
    14  func TestSetOrcidAttributesNew(t *testing.T) {
    15  	expected := http.StatusOK
    16  	id := randomCid()
    17  	attributes := randomOrcidAttributes()
    18  
    19  	status := client.SetOrcidAttributes(cfg.Endpoint, id, goodToken(cfg.Secret), attributes)
    20  	if status != expected {
    21  		t.Fatalf("Expected %v, got %v\n", expected, status)
    22  	}
    23  
    24  	status, current := client.GetOrcidAttributes(cfg.Endpoint, id, goodToken(cfg.Secret))
    25  	if status != expected {
    26  		t.Fatalf("Expected %v, got %v\n", expected, status)
    27  	}
    28  
    29  	if current == nil || len(current) == 0 {
    30  		t.Fatalf("Expected to find orcid for %s and did not\n", attributes.ID)
    31  	}
    32  
    33  	ensureIdenticalOrcidsAttributes(t, current[0], &attributes)
    34  }
    35  
    36  func TestSetOrcidAttributesUpdate(t *testing.T) {
    37  	expected := http.StatusOK
    38  	cid := randomCid()
    39  	attributes1 := randomOrcidAttributes()
    40  	attributes2 := randomOrcidAttributes()
    41  
    42  	status := client.SetOrcidAttributes(cfg.Endpoint, cid, goodToken(cfg.Secret), attributes1)
    43  	if status != expected {
    44  		t.Fatalf("Expected %v, got %v\n", expected, status)
    45  	}
    46  
    47  	status, current := client.GetOrcidAttributes(cfg.Endpoint, cid, goodToken(cfg.Secret))
    48  	if status != expected {
    49  		t.Fatalf("Expected %v, got %v\n", expected, status)
    50  	}
    51  
    52  	if current == nil || len(current) == 0 {
    53  		t.Fatalf("Expected to find orcid for %s and did not\n", attributes1.ID)
    54  	}
    55  
    56  	ensureIdenticalOrcidsAttributes(t, current[0], &attributes1)
    57  
    58  	status = client.SetOrcidAttributes(cfg.Endpoint, cid, goodToken(cfg.Secret), attributes2)
    59  	if status != expected {
    60  		t.Fatalf("Expected %v, got %v\n", expected, status)
    61  	}
    62  
    63  	status, current = client.GetOrcidAttributes(cfg.Endpoint, cid, goodToken(cfg.Secret))
    64  	if status != expected {
    65  		t.Fatalf("Expected %v, got %v\n", expected, status)
    66  	}
    67  
    68  	if current == nil || len(current) == 0 {
    69  		t.Fatalf("Expected to find orcid for %s and did not\n", attributes2.ID)
    70  	}
    71  
    72  	ensureIdenticalOrcidsAttributes(t, current[0], &attributes2)
    73  }
    74  
    75  func TestSetOrcidAttributesEmptyId(t *testing.T) {
    76  	expected := http.StatusBadRequest
    77  	attributes := randomOrcidAttributes()
    78  	status := client.SetOrcidAttributes(cfg.Endpoint, empty, goodToken(cfg.Secret), attributes)
    79  	if status != expected {
    80  		t.Fatalf("Expected %v, got %v\n", expected, status)
    81  	}
    82  }
    83  
    84  //func TestSetOrcidAttributesEmptyOrcid(t *testing.T) {
    85  //   expected := http.StatusBadRequest
    86  //   attributes := api.OrcidAttributes{ Orcid: empty }
    87  //   status := client.SetOrcidAttributes(cfg.Endpoint, goodCid, goodToken( cfg.Secret ), attributes )
    88  //   if status != expected {
    89  //      t.Fatalf("Expected %v, got %v\n", expected, status)
    90  //   }
    91  //}
    92  
    93  func TestSetOrcidAttributesEmptyToken(t *testing.T) {
    94  	expected := http.StatusBadRequest
    95  	attributes := randomOrcidAttributes()
    96  	status := client.SetOrcidAttributes(cfg.Endpoint, goodCid, empty, attributes)
    97  	if status != expected {
    98  		t.Fatalf("Expected %v, got %v\n", expected, status)
    99  	}
   100  }
   101  
   102  func TestSetOrcidAttributesBadToken(t *testing.T) {
   103  	expected := http.StatusForbidden
   104  	attributes := randomOrcidAttributes()
   105  	status := client.SetOrcidAttributes(cfg.Endpoint, goodCid, badToken(cfg.Secret), attributes)
   106  	if status != expected {
   107  		t.Fatalf("Expected %v, got %v\n", expected, status)
   108  	}
   109  }
   110  
   111  //
   112  // end of file
   113  //