github.com/Bio-core/jtree@v0.0.0-20190705165106-1d7a7e7d6272/repos/repos_test.go (about)

     1  package repos
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"net/http"
     7  	"testing"
     8  )
     9  
    10  var host = "http://127.0.0.1:8000"
    11  
    12  func TestUpdatePatientPOST(t *testing.T) {
    13  
    14  	patient := GetPatientByID("1")
    15  	first := "Mitchell"
    16  	last := "Strong"
    17  	patient.FirstName = &first
    18  	patient.LastName = &last
    19  	person1Bytes, err := json.Marshal(patient)
    20  
    21  	if err != nil {
    22  		t.Fail()
    23  		return
    24  	}
    25  
    26  	body := bytes.NewReader(person1Bytes)
    27  
    28  	req, err := http.NewRequest("POST", host+"/Jtree/metadata/0.1.0/patient", body)
    29  
    30  	if err != nil {
    31  		t.Fail()
    32  		return
    33  	}
    34  
    35  	req.Header.Set("Content-Type", "application/json")
    36  
    37  	resp, err := http.DefaultClient.Do(req)
    38  
    39  	if resp.Status != "201 Created" {
    40  		t.Fail()
    41  		return
    42  	}
    43  
    44  	if err != nil {
    45  		t.Fail()
    46  		return
    47  	}
    48  
    49  	defer resp.Body.Close()
    50  
    51  	patientNew := GetPatientByID("1")
    52  
    53  	if *patientNew.FirstName != first || *patientNew.LastName != last {
    54  		t.Fail()
    55  		return
    56  	}
    57  
    58  	return
    59  }