fix: overwrite test case when creating duplicated (#531)

Co-authored-by: rick <linuxsuren@users.noreply.github.com>
This commit is contained in:
Rick 2024-09-12 10:08:34 +08:00 committed by GitHub
parent d00314334b
commit e68c9961b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 11 deletions

View File

@ -131,6 +131,9 @@ const submitForm = async (formEl: FormInstance | undefined) => {
}, () => {
suiteCreatingLoading.value = false
emit('updated', props.name, testCaseForm.name)
}, (e) => {
suiteCreatingLoading.value = false
ElMessage.error('Oops, ' + e)
}
)

View File

@ -15,13 +15,15 @@ limitations under the License.
*/
import { Cache } from './cache'
function DefaultResponseProcess(response: any) {
async function DefaultResponseProcess(response: any) {
if (!response.ok) {
switch (response.status) {
case 401:
throw new Error("Unauthenticated")
}
throw new Error(response.statusText)
const message = await response.json().then((data :any) => data.message)
throw new Error(message)
} else {
return response.json()
}

View File

@ -349,7 +349,15 @@ func (l *fileLoader) GetTestCase(suite, name string) (testcase TestCase, err err
return
}
func (l *fileLoader) CreateTestCase(suiteName string, testcase TestCase) (err error) {
func (l *fileLoader) CreateTestCase(suiteName string, testcase TestCase) error {
return l.createOrUpdate(suiteName, testcase, false)
}
func (l *fileLoader) UpdateTestCase(suite string, testcase TestCase) error {
return l.createOrUpdate(suite, testcase, true)
}
func (l *fileLoader) createOrUpdate(suiteName string, testcase TestCase, update bool) (err error) {
var suite *TestSuite
var suiteFilepath string
for i := range l.paths {
@ -377,18 +385,14 @@ func (l *fileLoader) CreateTestCase(suiteName string, testcase TestCase) (err er
if !found {
suite.Items = append(suite.Items, testcase)
} else if !update {
err = fmt.Errorf("test case %s already exists", testcase.Name)
return
}
err = SaveTestSuiteToFile(suite, suiteFilepath)
}
return
}
func (l *fileLoader) UpdateTestCase(suite string, testcase TestCase) (err error) {
err = l.CreateTestCase(suite, testcase)
return
}
func (l *fileLoader) DeleteTestCase(suiteName, testcase string) (err error) {
var suite *TestSuite
var suiteFilepath string

View File

@ -1,5 +1,5 @@
/*
Copyright 2023 API Testing Authors.
Copyright 2023-2024 API Testing Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -189,6 +189,12 @@ func TestSuite(t *testing.T) {
})
assert.NoError(t, err)
// should failed when creating duplicated test case
err = writer.CreateTestCase("test", atest.TestCase{
Name: "login",
})
assert.Error(t, err)
var suite atest.TestSuite
suite, err = writer.GetTestSuite("test", false)
if assert.NoError(t, err) {