|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import AuthLogin from '../src/commands/auth/login'; |
| 3 | +import AuthLogout from '../src/commands/auth/logout'; |
| 4 | +import AuthWhoami from '../src/commands/auth/whoami'; |
| 5 | +import DataQuery from '../src/commands/data/query'; |
| 6 | +import DataGet from '../src/commands/data/get'; |
| 7 | +import DataCreate from '../src/commands/data/create'; |
| 8 | +import DataUpdate from '../src/commands/data/update'; |
| 9 | +import DataDelete from '../src/commands/data/delete'; |
| 10 | +import MetaList from '../src/commands/meta/list'; |
| 11 | +import MetaGet from '../src/commands/meta/get'; |
| 12 | +import MetaRegister from '../src/commands/meta/register'; |
| 13 | +import MetaDelete from '../src/commands/meta/delete'; |
| 14 | + |
| 15 | +describe('Remote API Commands (oclif)', () => { |
| 16 | + describe('Auth Commands', () => { |
| 17 | + it('should have auth login command', () => { |
| 18 | + expect(AuthLogin.description).toContain('Authenticate'); |
| 19 | + expect(AuthLogin.flags).toHaveProperty('url'); |
| 20 | + expect(AuthLogin.flags).toHaveProperty('email'); |
| 21 | + expect(AuthLogin.flags).toHaveProperty('password'); |
| 22 | + expect(AuthLogin.flags).toHaveProperty('json'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should have auth logout command', () => { |
| 26 | + expect(AuthLogout.description).toContain('Clear'); |
| 27 | + expect(AuthLogout.flags).toHaveProperty('json'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should have auth whoami command', () => { |
| 31 | + expect(AuthWhoami.description).toContain('session'); |
| 32 | + expect(AuthWhoami.flags).toHaveProperty('url'); |
| 33 | + expect(AuthWhoami.flags).toHaveProperty('token'); |
| 34 | + expect(AuthWhoami.flags).toHaveProperty('format'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('auth commands should have examples', () => { |
| 38 | + expect(AuthLogin.examples).toBeDefined(); |
| 39 | + expect(AuthLogin.examples.length).toBeGreaterThan(0); |
| 40 | + expect(AuthLogout.examples).toBeDefined(); |
| 41 | + expect(AuthWhoami.examples).toBeDefined(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('Data Commands', () => { |
| 46 | + it('should have data query command', () => { |
| 47 | + expect(DataQuery.description).toContain('Query'); |
| 48 | + expect(DataQuery.args).toHaveProperty('object'); |
| 49 | + expect(DataQuery.flags).toHaveProperty('filter'); |
| 50 | + expect(DataQuery.flags).toHaveProperty('fields'); |
| 51 | + expect(DataQuery.flags).toHaveProperty('sort'); |
| 52 | + expect(DataQuery.flags).toHaveProperty('limit'); |
| 53 | + expect(DataQuery.flags).toHaveProperty('offset'); |
| 54 | + expect(DataQuery.flags).toHaveProperty('format'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should have data get command', () => { |
| 58 | + expect(DataGet.description).toContain('single record'); |
| 59 | + expect(DataGet.args).toHaveProperty('object'); |
| 60 | + expect(DataGet.args).toHaveProperty('id'); |
| 61 | + expect(DataGet.flags).toHaveProperty('format'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should have data create command', () => { |
| 65 | + expect(DataCreate.description).toContain('Create'); |
| 66 | + expect(DataCreate.args).toHaveProperty('object'); |
| 67 | + expect(DataCreate.flags).toHaveProperty('data'); |
| 68 | + expect(DataCreate.flags).toHaveProperty('format'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should have data update command', () => { |
| 72 | + expect(DataUpdate.description).toContain('Update'); |
| 73 | + expect(DataUpdate.args).toHaveProperty('object'); |
| 74 | + expect(DataUpdate.args).toHaveProperty('id'); |
| 75 | + expect(DataUpdate.flags).toHaveProperty('data'); |
| 76 | + expect(DataUpdate.flags).toHaveProperty('format'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should have data delete command', () => { |
| 80 | + expect(DataDelete.description).toContain('Delete'); |
| 81 | + expect(DataDelete.args).toHaveProperty('object'); |
| 82 | + expect(DataDelete.args).toHaveProperty('id'); |
| 83 | + expect(DataDelete.flags).toHaveProperty('format'); |
| 84 | + }); |
| 85 | + |
| 86 | + it('data commands should support common flags', () => { |
| 87 | + const commands = [DataQuery, DataGet, DataCreate, DataUpdate, DataDelete]; |
| 88 | + commands.forEach(cmd => { |
| 89 | + expect(cmd.flags).toHaveProperty('url'); |
| 90 | + expect(cmd.flags).toHaveProperty('token'); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + it('data commands should have examples', () => { |
| 95 | + expect(DataQuery.examples).toBeDefined(); |
| 96 | + expect(DataQuery.examples.length).toBeGreaterThan(0); |
| 97 | + expect(DataGet.examples).toBeDefined(); |
| 98 | + expect(DataCreate.examples).toBeDefined(); |
| 99 | + expect(DataUpdate.examples).toBeDefined(); |
| 100 | + expect(DataDelete.examples).toBeDefined(); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + describe('Metadata Commands', () => { |
| 105 | + it('should have meta list command', () => { |
| 106 | + expect(MetaList.description).toContain('List metadata'); |
| 107 | + expect(MetaList.args).toHaveProperty('type'); |
| 108 | + expect(MetaList.flags).toHaveProperty('format'); |
| 109 | + }); |
| 110 | + |
| 111 | + it('should have meta get command', () => { |
| 112 | + expect(MetaGet.description).toContain('Get'); |
| 113 | + expect(MetaGet.args).toHaveProperty('type'); |
| 114 | + expect(MetaGet.args).toHaveProperty('name'); |
| 115 | + expect(MetaGet.flags).toHaveProperty('format'); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should have meta register command', () => { |
| 119 | + expect(MetaRegister.description).toContain('Register'); |
| 120 | + expect(MetaRegister.args).toHaveProperty('type'); |
| 121 | + expect(MetaRegister.flags).toHaveProperty('data'); |
| 122 | + expect(MetaRegister.flags).toHaveProperty('format'); |
| 123 | + }); |
| 124 | + |
| 125 | + it('should have meta delete command', () => { |
| 126 | + expect(MetaDelete.description).toContain('Delete'); |
| 127 | + expect(MetaDelete.args).toHaveProperty('type'); |
| 128 | + expect(MetaDelete.args).toHaveProperty('name'); |
| 129 | + expect(MetaDelete.flags).toHaveProperty('format'); |
| 130 | + }); |
| 131 | + |
| 132 | + it('meta commands should support common flags', () => { |
| 133 | + const commands = [MetaList, MetaGet, MetaRegister, MetaDelete]; |
| 134 | + commands.forEach(cmd => { |
| 135 | + expect(cmd.flags).toHaveProperty('url'); |
| 136 | + expect(cmd.flags).toHaveProperty('token'); |
| 137 | + }); |
| 138 | + }); |
| 139 | + |
| 140 | + it('meta commands should have examples', () => { |
| 141 | + expect(MetaList.examples).toBeDefined(); |
| 142 | + expect(MetaList.examples.length).toBeGreaterThan(0); |
| 143 | + expect(MetaGet.examples).toBeDefined(); |
| 144 | + expect(MetaRegister.examples).toBeDefined(); |
| 145 | + expect(MetaDelete.examples).toBeDefined(); |
| 146 | + }); |
| 147 | + }); |
| 148 | + |
| 149 | + describe('Command Conventions', () => { |
| 150 | + it('all remote commands should support --url flag with OBJECTSTACK_URL env var', () => { |
| 151 | + const commands = [ |
| 152 | + AuthLogin, AuthWhoami, |
| 153 | + DataQuery, DataGet, DataCreate, DataUpdate, DataDelete, |
| 154 | + MetaList, MetaGet, MetaRegister, MetaDelete |
| 155 | + ]; |
| 156 | + |
| 157 | + commands.forEach(cmd => { |
| 158 | + expect(cmd.flags).toHaveProperty('url'); |
| 159 | + expect(cmd.flags.url).toHaveProperty('env', 'OBJECTSTACK_URL'); |
| 160 | + }); |
| 161 | + }); |
| 162 | + |
| 163 | + it('authenticated commands should support --token flag with OBJECTSTACK_TOKEN env var', () => { |
| 164 | + const commands = [ |
| 165 | + AuthWhoami, |
| 166 | + DataQuery, DataGet, DataCreate, DataUpdate, DataDelete, |
| 167 | + MetaList, MetaGet, MetaRegister, MetaDelete |
| 168 | + ]; |
| 169 | + |
| 170 | + commands.forEach(cmd => { |
| 171 | + expect(cmd.flags).toHaveProperty('token'); |
| 172 | + expect(cmd.flags.token).toHaveProperty('env', 'OBJECTSTACK_TOKEN'); |
| 173 | + }); |
| 174 | + }); |
| 175 | + |
| 176 | + it('all commands should support output formatting', () => { |
| 177 | + const commands = [ |
| 178 | + AuthWhoami, |
| 179 | + DataQuery, DataGet, DataCreate, DataUpdate, DataDelete, |
| 180 | + MetaList, MetaGet, MetaRegister, MetaDelete |
| 181 | + ]; |
| 182 | + |
| 183 | + commands.forEach(cmd => { |
| 184 | + expect(cmd.flags).toHaveProperty('format'); |
| 185 | + }); |
| 186 | + }); |
| 187 | + }); |
| 188 | +}); |
0 commit comments