Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

backendTest.ts 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. import { Injector } from "../src/backend/Injector/Injector";
  2. import { FrontworkAdmin } from "../src/backend/Admin/Admin";
  3. import { T1, T2, Tiers } from "../src/backend/Types/Items";
  4. import { RPCSocket } from "rpclibrary";
  5. import { FrontcraftIfc, Auth, User, FrontcraftFeatureIfc, Raid, Character, Rank, Class, Race, SRPriority, Spec, Signup } from "../src/backend/Types/Types";
  6. import { SpecT } from "../src/backend/Types/PlayerSpecs";
  7. type protoAccount<C extends Class = Class> = {
  8. name: string,
  9. pwHash?: string
  10. rank: Rank,
  11. race: Race,
  12. class: C,
  13. spec: SpecT[C]
  14. }
  15. const trialsAndUp = {
  16. ADMIN: true,
  17. Guildmaster: true,
  18. Officer: true,
  19. Classleader: true,
  20. Raider: true,
  21. Trial: true,
  22. Social: false,
  23. Guest: false
  24. }
  25. const adminsOnly = {
  26. ADMIN: true,
  27. Guildmaster: true,
  28. Officer: true,
  29. Classleader: false,
  30. Raider: false,
  31. Trial: false,
  32. Social: false,
  33. Guest: false
  34. }
  35. const defaultPermissions = [
  36. {
  37. rpcname: 'signup', ...trialsAndUp
  38. }, {
  39. rpcname: 'reset', ...adminsOnly
  40. }, {
  41. rpcname: 'modifyPermissions', ...adminsOnly
  42. }, {
  43. rpcname: 'manageGuild', ...adminsOnly
  44. }, {
  45. rpcname: 'managePriorities', ...adminsOnly
  46. }, {
  47. rpcname: 'softreserveCurrency', ...adminsOnly
  48. }, {
  49. rpcname: 'manageRaid', ...adminsOnly
  50. }]
  51. const testAccounts: protoAccount[] = [
  52. {
  53. name: 'Rain',
  54. race: 'Human',
  55. class: 'Warrior',
  56. spec: 'Protection',
  57. rank: 'Guildmaster'
  58. }, {
  59. name: 'Celinda',
  60. class: 'Warrior',
  61. race: 'Night Elf',
  62. spec: 'Protection',
  63. rank: 'Officer'
  64. }, {
  65. name: 'Silver',
  66. class: 'Druid',
  67. race: 'Night Elf',
  68. spec: 'Restoration',
  69. rank: 'Trial'
  70. }, {
  71. name: 'Dagger',
  72. race: 'Dwarf',
  73. class: 'Rogue',
  74. spec: 'Assassination',
  75. rank: 'Classleader'
  76. }, {
  77. name: 'Hope',
  78. class: 'Paladin',
  79. race: 'Human',
  80. spec: 'Holy',
  81. rank: 'Classleader'
  82. }, {
  83. name: 'Shrekd',
  84. class: 'Warrior',
  85. race: 'Dwarf',
  86. spec: 'Fury',
  87. rank: 'Classleader'
  88. }, {
  89. name: 'Teeniweeni',
  90. class: 'Warlock',
  91. race: 'Gnome',
  92. spec: 'Demonology',
  93. rank: 'Classleader'
  94. }, {
  95. name: 'Hagibaba',
  96. class: 'Priest',
  97. race: 'Human',
  98. spec: 'Discipline',
  99. rank: 'Classleader'
  100. }, {
  101. name: 'Muffinbreak',
  102. class: 'Mage',
  103. race: 'Gnome',
  104. spec: 'Arcane',
  105. rank: 'Classleader'
  106. },
  107. ]
  108. describe('Frontcraft', () => {
  109. let auth: Auth,
  110. adminUser: User,
  111. server: FrontworkAdmin,
  112. client: RPCSocket & FrontcraftIfc,
  113. adminClient: RPCSocket & FrontcraftFeatureIfc,
  114. raids: Raid[] = [],
  115. users: { [username in string]: { account: User, character: Character, auth: Auth, signup?: Signup, item?: string } } = {}
  116. const createAccount = (user: User) => {
  117. return client.UserManager.createUser(user)
  118. }
  119. const createAccountAndUser = async (acc: protoAccount) => {
  120. const account = await createAccount({
  121. pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //sha256("a")
  122. rank: acc.rank,
  123. username: acc.name,
  124. })
  125. const auth = await client.UserManager.login(acc.name, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb')
  126. const id = await client.CharacterManager.getSpecId(acc.class, acc.spec)
  127. const char = await client.CharacterManager.createCharacter(auth.token.value, {
  128. charactername: acc.name,
  129. specid: id,
  130. userid: account.id!,
  131. race: acc.race
  132. })
  133. return {
  134. account: account,
  135. character: char,
  136. auth: auth
  137. }
  138. }
  139. before(function (done) {
  140. this.timeout(10000);
  141. server = Injector.resolve<FrontworkAdmin>(FrontworkAdmin)
  142. server.start().then((_server) => {
  143. RPCSocket.makeSocket<FrontcraftIfc>(20000, 'localhost').then(_client => {
  144. client = _client
  145. createAccount({
  146. pwhash: 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', //hash("a")
  147. rank: 'ADMIN',
  148. username: 'a',
  149. MC: 2
  150. }).then(adminUser => {
  151. client.UserManager.login(adminUser.username, 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb').then(auth => {
  152. const sock = new RPCSocket(
  153. auth.port,
  154. "localhost"
  155. )
  156. sock.connect<any>(auth.token.value).then(cli => {
  157. adminClient = cli
  158. sock.hook('kick', () => {
  159. console.log("I got kicked");
  160. })
  161. sock.hook('getUserData', () => auth)
  162. sock.hook('navigate', (where: string) => {
  163. console.log("Nagivate client to " + where);
  164. })
  165. sock.on('error', (e) => {
  166. console.log('Socket error', e)
  167. })
  168. done()
  169. })
  170. })
  171. })
  172. })
  173. }).catch(done)
  174. })
  175. after(() => {
  176. client.destroy()
  177. adminClient.destroy()
  178. server.stop()
  179. })
  180. it('create raids', (done) => {
  181. let insertRaid = <Raid>{
  182. description: "Test raid 1",
  183. title: 'BWL :D',
  184. start: Date.now().toString(),
  185. tier: 'BWL'
  186. }
  187. adminClient.manageRaid.createRaid(insertRaid).then(() => {
  188. client.RaidManager.getRaids().then((r) => {
  189. if (r[0].title === insertRaid.title
  190. && r[0].description === insertRaid.description
  191. && r[0].tier === "BWL") {
  192. raids.push(r[0])
  193. done()
  194. }
  195. }).catch(done)
  196. }).catch(done)
  197. })
  198. it('create users', (done) => {
  199. Promise.all(testAccounts.map(acc => createAccountAndUser(acc))).then(accs => {
  200. if (accs.length === testAccounts.length) {
  201. accs.forEach(acc => {
  202. users[acc.account.username] = acc
  203. })
  204. done()
  205. }
  206. }).catch(done)
  207. })
  208. it('should sign up', (done) => {
  209. Promise.all(Object.values(users).map((user) =>
  210. adminClient.signup.sign(user.auth.token.value, user.character, raids[0], false).catch(done)
  211. )).then(x => {
  212. adminClient.signup.getSignups(raids[0]).then(s => {
  213. if (s.length == testAccounts.length) {
  214. s.forEach(sign => {
  215. users[sign.username].signup = sign
  216. })
  217. done()
  218. } else {
  219. done("Unexpected number of signups: " + s.length)
  220. }
  221. })
  222. })
  223. })
  224. it('calculate priorities', (done) => {
  225. const makePrio = async (itemname: string, spec?: Spec, race?: Race, mod: number = 0, description: string = "") => {
  226. let specid
  227. if (spec)
  228. specid = await client.CharacterManager.getSpecId(spec.class, <any>spec.specname)
  229. await adminClient.managePriorities.setPriority(itemname, {
  230. specid: specid,
  231. race: race,
  232. modifier: mod,
  233. description: description
  234. })
  235. }
  236. Promise.all([
  237. makePrio(
  238. 'Quick Strike Ring',
  239. { class: 'Warrior', specname: 'Fury' },
  240. undefined, 2, "str-to-ap bias"
  241. ),
  242. makePrio(
  243. 'Quick Strike Ring',
  244. { class: 'Druid', specname: 'Feral (DPS)' },
  245. undefined, 2, "str-to-ap bias"
  246. ),
  247. makePrio(
  248. 'Band of Accuria',
  249. { class: 'Warrior', specname: 'Protection' },
  250. undefined, 2, "hit bias"
  251. ),
  252. makePrio(
  253. 'Bracers of Arcane Accuracy',
  254. { class: 'Warlock', specname: 'Demonology' },
  255. undefined, 2, "hit bias"
  256. ),
  257. makePrio(
  258. 'Bracers of Arcane Accuracy',
  259. { class: 'Warlock', specname: 'Affliction' },
  260. undefined, 2, "hit bias"
  261. ),
  262. makePrio(
  263. 'Bracers of Arcane Accuracy',
  264. { class: 'Warlock', specname: 'Destruction' },
  265. undefined, 2, "hit bias"
  266. ),
  267. makePrio(
  268. 'Bracers of Arcane Accuracy',
  269. { class: 'Mage', specname: 'Arcane' },
  270. undefined, 1, "hit bias"
  271. ),
  272. makePrio(
  273. 'Bracers of Arcane Accuracy',
  274. { class: 'Mage', specname: 'Frost' },
  275. undefined, 1, "hit bias"
  276. ),
  277. makePrio(
  278. 'Bracers of Arcane Accuracy',
  279. { class: 'Mage', specname: 'Fire' },
  280. undefined, 1, "hit bias"
  281. ),
  282. makePrio(
  283. 'Maladath, Runed Blade of the Black Flight',
  284. undefined,
  285. "Human", -2, "[1] Non-Human"
  286. ),
  287. makePrio(
  288. 'Maladath, Runed Blade of the Black Flight',
  289. { class: 'Rogue', specname: 'Combat' },
  290. undefined, 2, "Weapon skill bias"
  291. ),
  292. makePrio(
  293. 'Maladath, Runed Blade of the Black Flight',
  294. { class: 'Warrior', specname: 'Fury' },
  295. 'Human', 4, "+2 Fury Warrior (weapon skill bias), +2 to offset [1]"
  296. ),
  297. makePrio(
  298. 'Maladath, Runed Blade of the Black Flight',
  299. { class: 'Warrior', specname: 'Protection' },
  300. 'Human', 5, "+3 Prot Warrior, +2 to offset [1]"
  301. ),
  302. makePrio(
  303. 'Cloak of Firemaw',
  304. { class: 'Rogue', specname: 'Assassination' },
  305. undefined, 2, "agi-to-ap bias"
  306. ),
  307. makePrio(
  308. 'Cloak of Firemaw',
  309. { class: 'Rogue', specname: 'Combat' },
  310. undefined, 2, "agi-to-ap bias"
  311. ),
  312. makePrio(
  313. 'Cloak of Firemaw',
  314. { class: 'Rogue', specname: 'Subtlety' },
  315. undefined, 2, "agi-to-ap bias"
  316. ),
  317. makePrio(
  318. 'Band of Forced Concentration',
  319. { class: 'Warlock', specname: 'Demonology' },
  320. undefined, 2, "hit bias"
  321. ),
  322. makePrio(
  323. 'Band of Forced Concentration',
  324. { class: 'Warlock', specname: 'Affliction' },
  325. undefined, 2, "hit bias"
  326. ),
  327. makePrio(
  328. 'Band of Forced Concentration',
  329. { class: 'Warlock', specname: 'Destruction' },
  330. undefined, 2, "hit bias"
  331. ),
  332. makePrio(
  333. 'Band of Forced Concentration',
  334. { class: 'Mage', specname: 'Arcane' },
  335. undefined, 1, "hit bias"
  336. ),
  337. makePrio(
  338. 'Band of Forced Concentration',
  339. { class: 'Mage', specname: 'Frost' },
  340. undefined, 1, "hit bias"
  341. ),
  342. makePrio(
  343. 'Band of Forced Concentration',
  344. { class: 'Mage', specname: 'Fire' },
  345. undefined, 1, "hit bias"
  346. ),
  347. makePrio(
  348. 'Chromatic Boots',
  349. { class: 'Warrior', specname: 'Protection' },
  350. undefined, 2, "hit bias"
  351. ),
  352. makePrio(
  353. 'Crul\'shorukh, Edge of Chaos',
  354. undefined,
  355. "Human", -2, "Non-human"
  356. ),
  357. makePrio(
  358. 'Crul\'shorukh, Edge of Chaos',
  359. { class: 'Warrior', specname: 'Protection' },
  360. undefined, 2, "nice dps bias"
  361. ),
  362. makePrio(
  363. 'Crul\'shorukh, Edge of Chaos',
  364. { class: 'Warrior', specname: 'Fury' },
  365. undefined, 2, "nice dps bias"
  366. ),
  367. makePrio(
  368. 'Drake Talon Pauldrons',
  369. { class: 'Warrior', specname:'Protection'},
  370. undefined, 2, 'dodge + stats-to-threat bias'
  371. ),
  372. makePrio(
  373. 'Helm of Endless Rage',
  374. { class: 'Warrior', specname:'Protection'},
  375. undefined, 2, 'stats-to-threat bias'
  376. ),
  377. makePrio(
  378. 'Drake Fang Talisman',
  379. { class: 'Warrior', specname: 'Protection' },
  380. undefined, 5, "hit bias"
  381. ),
  382. makePrio(
  383. 'Drake Fang Talisman',
  384. { class: 'Rogue', specname: 'Assassination' },
  385. undefined, 4, "hit bias"
  386. ),
  387. makePrio(
  388. 'Drake Fang Talisman',
  389. { class: 'Rogue', specname: 'Combat' },
  390. undefined, 4, "hit bias"
  391. ),
  392. makePrio(
  393. 'Drake Fang Talisman',
  394. { class: 'Rogue', specname: 'Subtlety' },
  395. undefined, 4, "hit bias"
  396. ),
  397. makePrio(
  398. 'Drake Fang Talisman',
  399. { class: 'Warrior', specname: 'Fury' },
  400. undefined, 2, "hit bias"
  401. ),
  402. makePrio(
  403. 'Drake Fang Talisman',
  404. { class: 'Druid', specname: 'Feral (DPS)' },
  405. undefined, 2, "hit bias"
  406. ),
  407. makePrio(
  408. 'Circle of Applied Force',
  409. { class: 'Warrior', specname: 'Fury' },
  410. undefined, 2, "str-to-ap bias"
  411. ),
  412. makePrio(
  413. 'Circle of Applied Force',
  414. { class: 'Druid', specname: 'Feral (DPS)' },
  415. undefined, 3, "str-to-ap bias + agi-to-ap bias"
  416. ),
  417. makePrio(
  418. 'Empowered Leggings',
  419. { class: 'Paladin', specname: 'Holy' },
  420. undefined, 2, "crit bias"
  421. ),
  422. makePrio(
  423. 'Empowered Leggings',
  424. { class: 'Druid', specname: 'Restoration' },
  425. undefined, 2, "crit bias"
  426. ),
  427. makePrio(
  428. 'Boots of the Shadow Flame',
  429. { class: 'Rogue', specname: 'Assassination' },
  430. undefined, 2, "hit bias"
  431. ),
  432. makePrio(
  433. 'Boots of the Shadow Flame',
  434. { class: 'Rogue', specname: 'Combat' },
  435. undefined, 2, "hit bias"
  436. ),
  437. makePrio(
  438. 'Boots of the Shadow Flame',
  439. { class: 'Rogue', specname: 'Subtlety' },
  440. undefined, 2, "hit bias"
  441. ),
  442. makePrio(
  443. 'Boots of the Shadow Flame',
  444. { class: 'Druid', specname: 'Feral (DPS)' },
  445. undefined, 2, "hit bias"
  446. ),
  447. makePrio(
  448. 'Neltharion\'s Tear',
  449. { class: 'Warlock', specname: 'Demonology' },
  450. undefined, 4, "hit bias"
  451. ),
  452. makePrio(
  453. 'Neltharion\'s Tear',
  454. { class: 'Warlock', specname: 'Affliction' },
  455. undefined, 4, "hit bias"
  456. ),
  457. makePrio(
  458. 'Neltharion\'s Tear',
  459. { class: 'Warlock', specname: 'Destruction' },
  460. undefined, 4, "hit bias"
  461. ),
  462. makePrio(
  463. 'Neltharion\'s Tear',
  464. { class: 'Mage', specname: 'Arcane' },
  465. undefined, 2, "hit bias"
  466. ),
  467. makePrio(
  468. 'Neltharion\'s Tear',
  469. { class: 'Mage', specname: 'Frost' },
  470. undefined, 2, "hit bias"
  471. ),
  472. makePrio(
  473. 'Neltharion\'s Tear',
  474. { class: 'Mage', specname: 'Fire' },
  475. undefined, 2, "hit bias"
  476. ),
  477. makePrio(
  478. 'Cloak of Draconic Might',
  479. { class: 'Warrior', specname: 'Fury' },
  480. undefined, 2, "str-to-ap bias"
  481. ),
  482. makePrio(
  483. 'Cloak of Draconic Might',
  484. { class: 'Druid', specname: 'Feral (DPS)' },
  485. undefined, 3, "str-to-ap + agi-to-ap bias"
  486. ),
  487. ]).then(() => {
  488. const user = Object.values(users)[0]
  489. client.ItemManager.calculatePriorities("Maladath, Runed Blade of the Black Flight", user.character).then(sum => {
  490. if (sum === 3)
  491. done()
  492. else
  493. console.log("Expected prio on maladath to be 4, but was:", sum, user.character);
  494. })
  495. })
  496. })
  497. it('buy token', (done) => {
  498. Promise.all(Object.values(users).map(async (user) => {
  499. const itemname = "Maladath, Runed Blade of the Black Flight" //T1[Math.floor(T1.length*Math.random())]
  500. const modifier = await client.ItemManager.calculatePriorities(itemname, user.character)
  501. const token = await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!)
  502. users[user.account.username].item = itemname
  503. if (!token) return false
  504. return modifier + 1 === token.level
  505. })).then(success => {
  506. if (success.reduce((prev, curr) => prev && curr, true)) done()
  507. })
  508. })
  509. it('not buy token without currency', (done) => {
  510. const user = Object.values(users)[0]
  511. const itemname = "Maladath, Runed Blade of the Black Flight"
  512. client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!).then(token => {
  513. if (!token)
  514. done()
  515. else {
  516. console.log("Unexpected token", token);
  517. }
  518. })
  519. })
  520. it('upgrade token', (done) => {
  521. const user = Object.values(users)[0]
  522. const itemname = "Maladath, Runed Blade of the Black Flight"
  523. client.ItemManager.getItem(itemname).then(async item => {
  524. await adminClient.softreserveCurrency.incrementCurrency(user.account, item.tier, 2)
  525. const before = await client.ItemManager.getToken(user.character, item)
  526. if (!before || before.level !== 4) {
  527. console.log("expected level to be 4", before ? before.level : '?');
  528. return
  529. }
  530. await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!)
  531. const after = await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, user.signup!)
  532. if (!after || after.level !== 6) {
  533. console.log("expected level after to be 6", after ? after.level : '?');
  534. return
  535. }
  536. done()
  537. })
  538. })
  539. it('should buy more tokens', (done) => {
  540. Promise.all(Object.values(users).map(async (user) => {
  541. await adminClient.softreserveCurrency.incrementCurrency(user.account, raids[0].tier, 1)
  542. return await client.ItemManager
  543. .buyToken(
  544. user.auth.token.value,
  545. user.character.charactername,
  546. T2[Math.floor(T2.length * Math.random())],
  547. user.signup!
  548. )
  549. })).then(_ => {
  550. done()
  551. })
  552. })
  553. it('can set permissions', (done) => {
  554. Promise.all(
  555. defaultPermissions.map(perm => adminClient.modifyPermissions.setPermission(perm)),
  556. ).then(_ => {
  557. done()
  558. })
  559. })
  560. it('start raid', (done) => {
  561. client.RaidManager.getRaids().then((r) => {
  562. adminClient.manageRaid.startRaid(raids[0]).then(async data => {
  563. const dbRaids = await client.RaidManager.getRaids()
  564. if (dbRaids.length === 0) {
  565. await client.UserManager.getUser(testAccounts[0].name).then(dbUser => {
  566. if (dbUser && dbUser.BWL === 1) {
  567. adminClient.signup.getSignups(raids[0]).then(signups => {
  568. if (signups.length === 0) {
  569. done()
  570. } else {
  571. console.log(signups);
  572. }
  573. })
  574. }
  575. else {
  576. console.log("Bad user currency", dbUser);
  577. }
  578. })
  579. }
  580. })
  581. })
  582. })
  583. it('reset system', (done) => {
  584. adminClient.reset.wipeCurrencyAndItems().then(() => {
  585. client.UserManager.getUser(testAccounts[0].name).then(user => {
  586. if (user && user.MC === 1) {
  587. client.ItemManager.getTokens(users[testAccounts[0].name.toLowerCase()].character, ['BWL']).then(tokens => {
  588. if (tokens!.length === 0) {
  589. done()
  590. } else {
  591. console.log(tokens);
  592. }
  593. })
  594. } else {
  595. console.log(user)
  596. }
  597. })
  598. })
  599. })
  600. it('implements loot system correctly', (done) => {
  601. const ONE_WEEK = 4800000000
  602. const Raid = (week: number, tier: string) => {
  603. return <Raid>{
  604. description: tier + " Test raid 1",
  605. title: tier,
  606. start: (week * ONE_WEEK + Date.now()).toString(),
  607. tier: tier
  608. }
  609. }
  610. const user = Object.values(users)[0]
  611. const createRaid = adminClient.manageRaid.createRaid
  612. const sign = async (raid: Raid, late = false) => await adminClient.signup.sign(user.auth.token.value, user.character, raid, late)
  613. const buyToken = async (signup: Signup, itemname: string) => await client.ItemManager.buyToken(user.auth.token.value, user.character.charactername, itemname, signup)
  614. const getCurrency = async (tier: Tiers) => {
  615. const dbUser = await client.UserManager.getUser(user.account.username)
  616. return dbUser[tier]
  617. }
  618. createRaid(Raid(0, 'BWL')).then(async (BWL0: Raid) => {
  619. const T2_0 = await client.ItemManager.getItem(T2[0])
  620. //const BWL0 = await createRaid(Raid(0, 'BWL'))
  621. const signupBWL0 = await sign(BWL0)
  622. let BWL = await getCurrency(BWL0.tier)
  623. let token = await buyToken(signupBWL0, T2[0])
  624. const BWLAfter = await getCurrency(BWL0.tier)
  625. if (!token
  626. || BWL - BWLAfter != 1) {
  627. console.log("Bad Token status", BWL0, signupBWL0, BWL, BWLAfter)
  628. done(new Error("Bad Token status 0"))
  629. return
  630. }
  631. let reserves = await client.ItemManager.getTokens(user.character, [BWL0.tier], true)
  632. let streaks = await client.ItemManager.getTokens(user.character, [BWL0.tier], false)
  633. if (reserves!.length != 1
  634. || streaks!.length != 0
  635. || reserves![0].itemname !== T2_0.itemname
  636. || reserves![0].level !== 1) {
  637. console.log("Bad Token status 1", reserves, streaks);
  638. done(new Error("Bad Token status"))
  639. return
  640. }
  641. await adminClient.manageRaid.startRaid(BWL0)
  642. reserves = await client.ItemManager.getTokens(user.character, [BWL0.tier], true)
  643. streaks = await client.ItemManager.getTokens(user.character, [BWL0.tier], false)
  644. if (reserves!.length != 0
  645. || streaks!.length != 1
  646. || streaks![0].itemname !== T2[0]
  647. || streaks![0].level !== 1) {
  648. console.log("Bad Token status", reserves, streaks);
  649. done(new Error("Bad Token status 2"))
  650. return
  651. }
  652. const BWL1 = await createRaid(Raid(1, 'BWL'))
  653. let signupBWL1 = await sign(BWL1)
  654. BWL = await getCurrency(BWL1.tier)
  655. await adminClient.manageRaid.adminUnsign(user.character, BWL1)
  656. let afterUnsign = await getCurrency(BWL1.tier)
  657. if (BWL !== afterUnsign) {
  658. console.log("Expected currency to be equal", BWL, afterUnsign)
  659. done(new Error("Expected currency to be equal"))
  660. return
  661. }
  662. signupBWL1 = await sign(BWL1)
  663. BWL = await getCurrency(BWL1.tier)
  664. await buyToken(signupBWL1, T2[1])
  665. await adminClient.manageRaid.adminUnsign(user.character, BWL1)
  666. afterUnsign = await getCurrency(BWL1.tier)
  667. if (BWL !== afterUnsign) {
  668. console.log("Expected currency to be equal", BWL, afterUnsign)
  669. done(new Error("Expected currency to be equal"))
  670. return
  671. }
  672. signupBWL1 = await sign(BWL1)
  673. await buyToken(signupBWL1, T2[1])
  674. reserves = await client.ItemManager.getTokens(user.character, [BWL1.tier], true)
  675. streaks = await client.ItemManager.getTokens(user.character, [BWL1.tier], false)
  676. if (reserves!.length != 1
  677. || streaks!.length != 0
  678. || reserves![0].itemname !== T2[1]
  679. || reserves![0].level !== 1) {
  680. console.log("Bad Token status", reserves, streaks);
  681. done(new Error("Bad Token status 3"))
  682. return
  683. }
  684. BWL = await getCurrency(BWL1.tier)
  685. const data = await adminClient.manageRaid.startRaid(BWL1)
  686. const afterStart = await getCurrency(BWL1.tier)
  687. if (BWL != 0 || afterStart != 1) {
  688. console.log("Wrong currency values", BWL, afterStart)
  689. done(new Error("Wrong currency values"))
  690. return
  691. }
  692. done()
  693. }).catch(e => {
  694. console.log(e);
  695. done(e)
  696. })
  697. })
  698. })