-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcookie.test.ts
More file actions
80 lines (68 loc) · 2.39 KB
/
cookie.test.ts
File metadata and controls
80 lines (68 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import { it } from '@effect/vitest';
import { expect } from 'vitest';
import {
getElementFromCookie,
incrementCookieHeader,
parseCookieHeaderForIndex,
} from '../cookie.js';
import { HeaderTypes } from '../../types/index.js';
import { Effect, Exit } from 'effect';
import { responseMap } from '../../responses/index.js';
import { returnSuccessResponseRedirect } from '../../responses/return-success-redirect.js';
import { NoSuchElementException } from 'effect/Cause';
it.effect('should parse a cookie header for an index value', () =>
Effect.gen(function* () {
const header: HeaderTypes = {
cookie: 'stepIndex=1',
};
const result = yield* parseCookieHeaderForIndex(header);
expect(result).toEqual('1');
}),
);
it.effect('should parse a cookie header for an index value', () =>
Effect.gen(function* () {
const header: HeaderTypes = {
cookie: '',
};
const result = yield* parseCookieHeaderForIndex(header).pipe(Effect.exit);
expect(result).toEqual(Exit.fail(new NoSuchElementException()));
}),
);
it('should increment the cookie header', () => {
const headers: HeaderTypes = {
cookie: 'stepIndex=1',
};
const result = incrementCookieHeader(headers);
expect(result).toEqual('2');
});
it('should return 1 if no cookie header passed to incrementCookieHeader', () => {
const headers: HeaderTypes = {};
const result = incrementCookieHeader(headers);
expect(result).toEqual('1');
});
it('should get an element from the response map based off the cookie header', () =>
Effect.gen(function* () {
const headers: HeaderTypes = {
cookie: 'stepIndex=1',
};
const expected = responseMap['UsernamePassword'][1];
const result = yield* getElementFromCookie(responseMap['UsernamePassword'], headers);
expect(expected).toEqual(result);
}));
it.effect('should return responesRedirect when we have exceeded the index for a given flow', () =>
Effect.gen(function* () {
const headers: HeaderTypes = {
cookie: 'stepIndex=4',
};
const arr = responseMap['UsernamePassword'];
const expected = returnSuccessResponseRedirect;
const result = yield* getElementFromCookie(arr, headers);
expect(expected).toEqual(result);
}),
);