about summary refs log tree commit diff stats
path: root/tests
Commit message (Expand)AuthorAgeFilesLines
* Added test for quoted freetext in parserJames Booth2013-07-201-0/+13
* Added parser testsJames Booth2013-07-141-0/+131
* Merge branch 'master' into unicodeJames Booth2013-07-131-3/+3
|\
| * Down arrow adds current line to history and shows empty lineJames Booth2013-07-131-3/+3
* | Moved functions to parser.c, moved parser to toolsJames Booth2013-07-111-1/+1
|/
* Fixed roster testsJames Booth2013-06-231-70/+68
* Removed contact_list, moved roster logic to xmpp/roster moduleJames Booth2013-05-061-1/+1
* Renamed contact_list_ functions to roster_James Booth2013-05-063-89/+89
* Fixed testsJames Booth2013-02-171-54/+54
* Removed invalid testsJames Booth2013-02-141-39/+0
* Only create contacts resource when onlineJames Booth2013-02-101-101/+58
* Renamed contact property jid->barejidJames Booth2013-02-091-19/+19
* Fixed testsJames Booth2013-02-023-3/+3
* Renamed parser.c -> command_parser.cJames Booth2013-01-282-92/+92
* Renamed history modulesJames Booth2013-01-283-5/+5
* Renamed create jid function using barejid and resourceJames Booth2013-01-271-2/+2
* Fixed jid handling to allow @ and / in resourceJames Booth2013-01-261-0/+48
* Got rid of old naming convention on prof_autocompleteJames Booth2013-01-253-57/+57
* Updated /info command for chat and private chatJames Booth2013-01-201-4/+4
* Command parser handles quotes argumentsJames Booth2013-01-141-0/+107
* Added jid_create_room_jidJames Booth2013-01-131-0/+16
* Changed Jid typedef to be explicit pointerJames Booth2013-01-131-17/+17
* Added jid datatypeJames Booth2013-01-123-0/+130
* Autocomplete: added free functionJames Booth2013-01-111-4/+4
* Fixed contact list testJames Booth2012-11-281-61/+61
* Commands now use parser function to handle parametersJames Booth2012-11-181-41/+25
* Handle commands with min 0 argsJames Booth2012-11-181-0/+26
* Added command parser for commands accepting free textJames Booth2012-11-181-0/+66
* Added parser moduleJames Booth2012-11-183-0/+129
* Removed old chat session testsJames Booth2012-11-013-75/+0
* Merge branch 'master' into chatstatesJames Booth2012-10-302-438/+101
|\
| * Fixed testsJames Booth2012-10-292-438/+101
* | Merge branch 'master' into type_outJames Booth2012-10-223-74/+74
|\|
| * Refactored parameter autocompletersJames Booth2012-10-221-18/+18
| * Removed trailing whitespace from src and testsJames Booth2012-10-213-56/+56
* | Basic chat session statesJames Booth2012-10-041-7/+55
* | Started work on chat session, and chat statesJames Booth2012-10-033-0/+27
|/
* Merge common and utilJames Booth2012-08-233-5/+5
* Added autobuild toolsJames Booth2012-07-016-0/+1316
hlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"net/url"
	"strings"
	"testing"

	"github.com/getwtxt/registry"
)

var apiPostUserCases = []struct {
	name    string
	nick    string
	uri     string
	wantErr bool
}{
	{
		name:    "Known Good User",
		nick:    "gbmor",
		uri:     "https://gbmor.dev/twtxt.txt",
		wantErr: false,
	},
	{
		name:    "Missing URI",
		nick:    "missinguri",
		uri:     "",
		wantErr: true,
	},
	{
		name:    "Missing Nickname",
		nick:    "",
		uri:     "https://example.com/twtxt.txt",
		wantErr: true,
	},
	{
		name:    "Missing URI and Nickname",
		nick:    "",
		uri:     "",
		wantErr: true,
	},
}

func Test_apiPostUser(t *testing.T) {
	initTestConf()
	portnum := fmt.Sprintf(":%v", confObj.Port)
	twtxtCache = registry.NewIndex()

	for _, tt := range apiPostUserCases {
		t.Run(tt.name, func(t *testing.T) {
			params := url.Values{}
			params.Set("url", tt.uri)
			params.Set("nickname", tt.nick)

			req, err := http.NewRequest("POST", "https://localhost"+portnum+"/api/plain/users", strings.NewReader(params.Encode()))
			if err != nil {
				t.Errorf("%v\n", err)
			}

			req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
			rr := httptest.NewRecorder()
			apiEndpointPOSTHandler(rr, req)

			if !tt.wantErr {
				if rr.Code != http.StatusOK {
					t.Errorf("Received unexpected non-200 response: %v\n", rr.Code)
				}
			} else {
				if rr.Code != http.StatusBadRequest {
					t.Errorf("Expected 400 Bad Request, but received: %v\n", rr.Code)
				}
			}
		})
	}
}