File size: 1,701 Bytes
391c43e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { describe, it, expect } from 'vitest';
import { shouldAutoCreateFirstProject } from '../first-run';

describe('shouldAutoCreateFirstProject', () => {
  it('returns true for a fresh visitor with no params and no projects', () => {
    expect(shouldAutoCreateFirstProject({ search: '', projectCount: 0 })).toBe(true);
  });

  it('returns false when the user already has projects', () => {
    expect(shouldAutoCreateFirstProject({ search: '', projectCount: 2 })).toBe(false);
  });

  it('returns false when a specific project is targeted', () => {
    expect(shouldAutoCreateFirstProject({ search: '?project=abc', projectCount: 0 })).toBe(false);
  });

  it('returns false during an OAuth return (?code=)', () => {
    expect(shouldAutoCreateFirstProject({ search: '?code=xyz', projectCount: 0 })).toBe(false);
  });

  it('returns false when a doc is targeted', () => {
    expect(shouldAutoCreateFirstProject({ search: '?doc=whats-new', projectCount: 0 })).toBe(false);
  });

  it('returns false when settings is targeted', () => {
    expect(shouldAutoCreateFirstProject({ search: '?settings=1', projectCount: 0 })).toBe(false);
  });

  it('returns false on a failed OAuth return (?error=, no code)', () => {
    expect(shouldAutoCreateFirstProject({ search: '?error=access_denied', projectCount: 0 })).toBe(false);
  });

  it('returns false for an empty-valued param (has() still matches)', () => {
    expect(shouldAutoCreateFirstProject({ search: '?project=', projectCount: 0 })).toBe(false);
  });

  it('returns false when multiple relevant params are combined', () => {
    expect(shouldAutoCreateFirstProject({ search: '?code=x&doc=y', projectCount: 0 })).toBe(false);
  });
});