refactor(account): isRowMissing als gemeinsame Hilfsfunktion statt dreier Kopien
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0ad51bf7c6
commit
04404ffdae
5 files changed
+40
-22
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { errorMessage, errorType, isInvalidLinkError, isUnauthorized, type ErrorContext } from './errors';
|
||||
import { errorMessage, errorType, isInvalidLinkError, isRowMissing, isUnauthorized, type ErrorContext } from './errors';
|
||||
|
||||
/** Fehler wie vom SDK (AppwriteException): Felder code, type, message. */
|
||||
const fail = (code: number, type: string, message = '') => ({ code, type, message });
|
||||
@@ -149,6 +149,33 @@ describe('errorType', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isRowMissing', () => {
|
||||
it('404 mit row_not_found heißt: die Zeile gibt es nicht (oder nicht für mich)', () => {
|
||||
expect(isRowMissing(fail(404, 'row_not_found'))).toBe(true);
|
||||
});
|
||||
|
||||
it('404 ohne Typ (leer oder fehlend) zählt ebenso', () => {
|
||||
expect(isRowMissing(fail(404, ''))).toBe(true);
|
||||
expect(isRowMissing({ code: 404 })).toBe(true);
|
||||
});
|
||||
|
||||
it('eine fehlende Tabelle, Datenbank oder Datei ist ein echter Fehler, kein „Zeile weg“', () => {
|
||||
for (const type of ['table_not_found', 'database_not_found', 'storage_file_not_found']) {
|
||||
expect(isRowMissing(fail(404, type)), type).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('andere Status und Nicht-Fehler nicht', () => {
|
||||
expect(isRowMissing(fail(401, 'row_not_found'))).toBe(false);
|
||||
expect(isRowMissing(fail(500, 'row_not_found'))).toBe(false);
|
||||
expect(isRowMissing({ code: '404', type: 'row_not_found' })).toBe(false);
|
||||
expect(isRowMissing(new TypeError('Failed to fetch'))).toBe(false);
|
||||
expect(isRowMissing('row_not_found')).toBe(false);
|
||||
expect(isRowMissing(null)).toBe(false);
|
||||
expect(isRowMissing(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isInvalidLinkError (Passwort-neu-Seite)', () => {
|
||||
it('Link-Fehler', () => {
|
||||
expect(isInvalidLinkError(fail(401, 'user_invalid_token'))).toBe(true);
|
||||
|
||||
Reference in new issue
Block a user