github.com/decred/politeia@v1.4.0/politeiad/backendv2/tstorebe/plugins/pi/proposalstatus_test.go (about)

     1  // Copyright (c) 2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package pi
     6  
     7  import (
     8  	"testing"
     9  	"time"
    10  
    11  	backend "github.com/decred/politeia/politeiad/backendv2"
    12  	"github.com/decred/politeia/politeiad/plugins/pi"
    13  	"github.com/decred/politeia/politeiad/plugins/ticketvote"
    14  )
    15  
    16  func TestProposalStatus(t *testing.T) {
    17  	// Setup tests
    18  	var tests = []struct {
    19  		name           string // Test name
    20  		state          backend.StateT
    21  		status         backend.StatusT
    22  		voteStatus     ticketvote.VoteStatusT
    23  		voteMD         *ticketvote.VoteMetadata
    24  		bscs           []pi.BillingStatusChange
    25  		proposalStatus pi.PropStatusT // Expected proposal status
    26  	}{
    27  		{
    28  			"unvetted",
    29  			backend.StateUnvetted,
    30  			backend.StatusUnreviewed,
    31  			ticketvote.VoteStatusInvalid,
    32  			nil,
    33  			nil,
    34  			pi.PropStatusUnvetted,
    35  		},
    36  		{
    37  			"unvetted-censored",
    38  			backend.StateUnvetted,
    39  			backend.StatusCensored,
    40  			ticketvote.VoteStatusInvalid,
    41  			nil,
    42  			nil,
    43  			pi.PropStatusUnvettedCensored,
    44  		},
    45  		{
    46  			"unvetted-abandoned",
    47  			backend.StateUnvetted,
    48  			backend.StatusArchived,
    49  			ticketvote.VoteStatusInvalid,
    50  			nil,
    51  			nil,
    52  			pi.PropStatusUnvettedAbandoned,
    53  		},
    54  		{
    55  			"abandoned",
    56  			backend.StateVetted,
    57  			backend.StatusArchived,
    58  			ticketvote.VoteStatusInvalid,
    59  			nil,
    60  			nil,
    61  			pi.PropStatusAbandoned,
    62  		},
    63  		{
    64  			"censored",
    65  			backend.StateVetted,
    66  			backend.StatusCensored,
    67  			ticketvote.VoteStatusInvalid,
    68  			nil,
    69  			nil,
    70  			pi.PropStatusCensored,
    71  		},
    72  		{
    73  			"under-review",
    74  			backend.StateVetted,
    75  			backend.StatusPublic,
    76  			ticketvote.VoteStatusUnauthorized,
    77  			nil,
    78  			nil,
    79  			pi.PropStatusUnderReview,
    80  		},
    81  		{
    82  			"vote-authorized",
    83  			backend.StateVetted,
    84  			backend.StatusPublic,
    85  			ticketvote.VoteStatusAuthorized,
    86  			nil,
    87  			nil,
    88  			pi.PropStatusVoteAuthorized,
    89  		},
    90  		{
    91  			"vote-started",
    92  			backend.StateVetted,
    93  			backend.StatusPublic,
    94  			ticketvote.VoteStatusStarted,
    95  			nil,
    96  			nil,
    97  			pi.PropStatusVoteStarted,
    98  		},
    99  		{
   100  			"approved",
   101  			backend.StateVetted,
   102  			backend.StatusPublic,
   103  			ticketvote.VoteStatusApproved,
   104  			&ticketvote.VoteMetadata{
   105  				LinkBy: time.Now().Unix() + 600, // 10m in the future
   106  			},
   107  			nil,
   108  			pi.PropStatusApproved,
   109  		},
   110  		{
   111  			"closed",
   112  			backend.StateVetted,
   113  			backend.StatusPublic,
   114  			ticketvote.VoteStatusApproved,
   115  			nil,
   116  			[]pi.BillingStatusChange{
   117  				{
   118  					Status: pi.BillingStatusClosed,
   119  				},
   120  			},
   121  			pi.PropStatusClosed,
   122  		},
   123  		{
   124  			"completed",
   125  			backend.StateVetted,
   126  			backend.StatusPublic,
   127  			ticketvote.VoteStatusApproved,
   128  			nil,
   129  			[]pi.BillingStatusChange{
   130  				{
   131  					Status: pi.BillingStatusCompleted,
   132  				},
   133  			},
   134  			pi.PropStatusCompleted,
   135  		},
   136  		{
   137  			"multi_active",
   138  			backend.StateVetted,
   139  			backend.StatusPublic,
   140  			ticketvote.VoteStatusApproved,
   141  			nil,
   142  			[]pi.BillingStatusChange{
   143  				{
   144  					Status: pi.BillingStatusCompleted,
   145  				},
   146  				{
   147  					Status: pi.BillingStatusActive,
   148  				},
   149  			},
   150  			pi.PropStatusActive,
   151  		},
   152  		{
   153  			"invalid",
   154  			backend.StateUnvetted,
   155  			backend.StatusPublic,
   156  			ticketvote.VoteStatusApproved,
   157  			nil,
   158  			nil,
   159  			pi.PropStatusInvalid,
   160  		},
   161  	}
   162  
   163  	// Run tests
   164  	for _, tc := range tests {
   165  		t.Run(tc.name, func(t *testing.T) {
   166  			// Run test
   167  			status, _ := proposalStatus(tc.state, tc.status,
   168  				tc.voteStatus, tc.voteMD, tc.bscs)
   169  
   170  			// Check if received proposal status euqal to the expected.
   171  			if tc.proposalStatus != status {
   172  				t.Errorf("want proposal status %v, got '%v'", tc.proposalStatus,
   173  					status)
   174  			}
   175  		})
   176  	}
   177  }