Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.35 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. require "swagger_helper"
  4.  
  5. describe "Shop API relocations" do
  6. before :all do
  7. @password = Faker::Internet.password(10, 20, true)
  8. @user = create(:user, password: @password)
  9. @company = create(:company)
  10. @shop = create(:shop, company_id: @company.id)
  11.  
  12. @user_company = create(:user_company, user_id: @user.id, company_id: @company.id)
  13. @user_shop = create(:user_shop, user_id: @user.id, shop_id: @shop.id)
  14. @user.set_company_admin_accesses(@company.id)
  15.  
  16. end
  17.  
  18. ### INDEX ###
  19. path "/companies/{company_id}/shops/{shop_id}/relocations" do
  20. get "Get relocations list" do
  21. tags "Relocations"
  22. security [bearerAuth: {}]
  23. consumes "application/json"
  24.  
  25. parameter name: :company_id, in: :path, type: :string, format: :uuid
  26. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  27. parameter name: :status, in: :query, type: :string, enum: ["saved", "deleted"]
  28. parameter name: :from_date, in: :query, type: :string, format: :date
  29. parameter name: :to_date, in: :query, type: :string, format: :date
  30. parameter name: :sender_stock_id, in: :query, type: :string, format: :uuid
  31. parameter name: :receiver_stock_id, in: :query, typr: :string, format: :uuid
  32. parameter name: :user_id, in: :query, type: :string, format: :uuid
  33. parameter name: :sort, in: :query, type: :string, enum: ["created_at", "number"]
  34. parameter name: :asc, in: :query, type: :string, enum: ["1", "0"]
  35. parameter name: :page, in: :query, type: :integer
  36.  
  37. response "200", "List of relocations" do
  38. schema type: :object,
  39. required: [:data],
  40. properties: {
  41. data: {
  42. type: :object,
  43. required: [:relocations, :total, :total_cost, :total_additional_cost],
  44. properties: {
  45. relocations: {
  46. type: :array,
  47. items: {
  48. type: :object,
  49. required: [:id, :number, :date, :user_id, :user_name, :sender_stock_id, :sender_stock_name, :receiver_stock_id, :receiver_stock_name, :total_cost, :additional_cost, :total],
  50. properties: {
  51. id: { type: :string, format: :uuid },
  52. number: { type: :string },
  53. date: { type: :string, format: "date-time" },
  54. user_id: { type: :string, format: :uuid },
  55. user_name: { type: :string },
  56. sender_stock_id: { type: :string, format: :uuid },
  57. sender_stock_name: { type: :string },
  58. receiver_stock_id: { type: :string, format: :uuid },
  59. receiver_stock_name: { type: :string },
  60. total_cost: { type: :number, format: :float },
  61. additional_cost: { type: :number, format: :float },
  62. total: { type: :number, format: :float }
  63. }
  64. }
  65. },
  66. total: { type: :number, format: :float },
  67. total_cost: { type: :number, format: :float },
  68. total_additional_cost: { type: :number, format: :float },
  69. meta: {
  70. type: :object,
  71. required: [:current_page, :total_pages, :limit_value, :total_items, :mapping_id, :mapping_columns],
  72. properties: {
  73. current_page: { type: :integer, format: :int32 },
  74. total_pages: { type: :integer, format: :int32 },
  75. limit_value: { type: :integer, format: :int32 },
  76. total_items: { type: :integer, format: :int32 },
  77. mapping_id: { type: :string },
  78. mapping_columns: {
  79. type: :array,
  80. items: {
  81. type: :object,
  82. required: [:prop, :width, :visible],
  83. properties: {
  84. prop: { type: :string },
  85. width: { type: :number, format: :float },
  86. visible: { type: :boolean }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95.  
  96. it "get list of relocations" do
  97. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  98. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  99. get "/v1/companies/#{@company.id}/shops/#{@shop.id}/relocations?sort=created_at&asc=1", headers: auth_headers
  100.  
  101. expect(response).to have_http_status(200)
  102. end
  103. end
  104.  
  105. end
  106.  
  107. end
  108.  
  109. ### NEW ###
  110. path "/companies/{company_id}/shops/{shop_id}/relocations/new" do
  111. get "info for create relocation " do
  112. tags "Relocations"
  113. security [bearerAuth: {}]
  114. consumes "application/json"
  115.  
  116. parameter name: :company_id, in: :path, type: :string, format: :uuid
  117. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  118.  
  119. response "200", "info for create" do
  120. schema type: :object,
  121. required: [:data],
  122. properties: {
  123. data: {
  124. type: :object,
  125. required: [:stocks, :meta],
  126. properties: {
  127. stocks: {
  128. type: :array,
  129. items: {
  130. type: :object,
  131. required: [:id, :name],
  132. properties: {
  133. id: { type: :string, format: :uuid },
  134. name: { type: :string }
  135. }
  136. }
  137. },
  138. meta: {
  139. type: :object,
  140. required: [:mapping_id, :mapping_columns],
  141. properties: {
  142. mapping_id: { type: :string },
  143. mapping_columns: {
  144. type: :array,
  145. items: {
  146. type: :object,
  147. required: [:prop, :width, :visible],
  148. properties: {
  149. prop: { type: :string },
  150. width: { type: :number, format: :float },
  151. visible: { type: :boolean }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160.  
  161. it "info for create" do
  162. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  163. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  164. get "/v1/companies/#{@company.id}/shops/#{@shop.id}/relocations/new", headers: auth_headers
  165.  
  166. expect(response).to have_http_status(200)
  167. end
  168. end
  169. end
  170. end
  171.  
  172. ### SEARCH ###
  173. path "/companies/{company_id}/shops/{shop_id}/relocations/search" do
  174. get "Search variants" do
  175. tags "Relocations"
  176. security [bearerAuth: {}]
  177. consumes "application/json"
  178.  
  179. parameter name: :company_id, in: :path, type: :string, format: :uuid
  180. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  181. parameter name: :date, in: :query, type: :string, format: :date
  182. parameter name: :sender_stock_id, in: :query, type: :string, format: :uuid
  183. parameter name: :q, in: :query, type: :string
  184.  
  185. response "200", "Search variants" do
  186. schema type: :object,
  187. required: [:data],
  188. properties: {
  189. data: {
  190. type: :object,
  191. required: [:variants],
  192. properties: {
  193. variants: {
  194. type: :array,
  195. items: {
  196. type: :object,
  197. required: [:id, :product_id, :name, :sku, :unit_id, :category_id, :shop_tax_id, :product_vendor_codes, :product_barcodes, :product_packs, :active_invoices],
  198. properties: {
  199. id: { type: :string, format: :uuid },
  200. product_id: { type: :string, format: :uuid },
  201. name: { type: :string },
  202. sku: { type: :string },
  203. unit_id: { type: :string, format: :uuid },
  204. category_id: { type: :string, format: :uuid },
  205. shop_tax_id: { type: :string, format: :uuid },
  206. product_vendor_codes: {
  207. type: :array,
  208. items: {
  209. type: :object,
  210. required: [:vendor_code],
  211. properties: {
  212. vendor_code: { type: :string }
  213. }
  214. }
  215. },
  216. product_barcodes: {
  217. type: :array,
  218. items: {
  219. type: :object,
  220. required: [ :barcode_type, :barcode ],
  221. properties: {
  222. barcode_type: { type: :string },
  223. barcode: { type: :string }
  224. }
  225. }
  226. },
  227. product_packs: {
  228. type: :array,
  229. items: {
  230. type: :object,
  231. required: [:id, :name, :count],
  232. properties: {
  233. id: { type: :string, format: :uuid },
  234. name: { type: :string },
  235. count: { type: :number, format: :float }
  236. }
  237. }
  238. },
  239. active_invoices: {
  240. type: :array,
  241. items: {
  242. type: :object,
  243. required: [:id, :stock_id, :price, :balance, :expiration_date, :document_date, :document_number, :document_type],
  244. properties: {
  245. id: { type: :string, format: :uuid },
  246. stock_id: { type: :string, format: :uuid },
  247. price: { type: :number, format: :float },
  248. balance: { type: :number, format: :float },
  249. expiration_date: { type: :string, format: "date-time" },
  250. document_date: { type: :string, format: "date-time" },
  251. document_number: { type: :integer, format: :int32 },
  252. document_type: { type: :string, enum: ["relocation", "inventory", "invoice"] }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. }
  260. }
  261. }
  262.  
  263. it "get list of variant by search query" do
  264. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  265. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  266. get "/v1/companies/#{@company.id}/shops/#{@shop.id}/relocations/search", headers: auth_headers
  267.  
  268. expect(response).to have_http_status(200)
  269. end
  270. end
  271.  
  272. end
  273. end
  274.  
  275. ### CREATE ###
  276. path "/companies/{company_id}/shops/{shop_id}/relocations" do
  277. post "Create relocation " do
  278. tags "Relocations"
  279. security [bearerAuth: {}]
  280. consumes "application/json"
  281.  
  282. parameter name: :company_id, in: :path, type: :string, format: :uuid
  283. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  284. parameter name: :body, in: :body, schema: {
  285. type: :object,
  286. required: [:relocation],
  287. properties: {
  288. relocation: {
  289. type: :object,
  290. required: [:date, :sender_stock_id, :receiver_stock_id, :note, :relocation_products],
  291. properties: {
  292. date: { type: :string, format: "date-time" },
  293. sender_stock_id: { type: :string, format: :uuid },
  294. receiver_stock_id: { type: :string, format: :uuid },
  295. note: { type: :string },
  296. relocation_products: {
  297. type: :array,
  298. items: {
  299. type: :object,
  300. required: [:variant_id, :object_product_id, :count, :additional_cost],
  301. properties: {
  302. variant_id: { type: :string, format: :uuid },
  303. object_product_id: { type: :string, format: :uuid },
  304. product_pack_id: { type: :string, format: :uuid },
  305. count: { type: :number, format: :float },
  306. additional_cost: { type: :number, format: :float }
  307. }
  308. }
  309. }
  310. }
  311. }
  312. }
  313. }
  314.  
  315. response "201", "create relocation" do
  316. schema type: :object,
  317. required: [:data],
  318. properties: {
  319. data: {
  320. type: :object,
  321. required: [:relocation],
  322. properties: {
  323. relocation: {
  324. type: :object,
  325. required: [:id, :number, :sender_stock_id, :sender_stock_name, :receiver_stock_id, :receiver_stock_name, :date, :user_id, :user_name, :status, :total_cost, :additional_cost, :total, :note, :relocation_products],
  326. properties: {
  327. id: { type: :string, format: :uuid },
  328. number: { type: :integer },
  329. sender_stock_id: { type: :string, format: :uuid },
  330. sender_stock_name: { type: :string },
  331. receiver_stock_id: { type: :string, format: :uuid },
  332. receiver_stock_name: { type: :string },
  333. date: { type: :string, format: "date-time" },
  334. user_id: { type: :string, format: :uuid },
  335. user_name: { type: :string },
  336. status: { type: :string },
  337. total_cost: { type: :number, format: :float },
  338. additional_cost: { type: :number, format: :float },
  339. total: { type: :number, format: :float },
  340. note: { type: :string },
  341. relocation_products: {
  342. type: :array,
  343. items: {
  344. type: :object,
  345. required: [:id, :variant_id, :product_id, :name, :sku, :unit_id, :category_id, :shop_tax_id, :product_pack_id, :count, :amount, :purchase_price, :additional_cost, :document_price, :currency_id, :expiration_date, :balance, :product_vendor_codes, :product_barcodes, :product_packs],
  346. properties: {
  347. id: { type: :string, format: :uuid },
  348. variant_id: { type: :string, format: :uuid },
  349. product_id: { type: :string, format: :uuid },
  350. name: { type: :string },
  351. sku: { type: :string },
  352. unit_id: { type: :string, format: :uuid },
  353. category_id: { type: :string, format: :uuid },
  354. shop_tax_id: { type: :string, format: :uuid },
  355. product_pack_id: { type: :string, format: :uuid },
  356. count: { type: :number, format: :float },
  357. amount: { type: :number, format: :float },
  358. purchase_price: { type: :number, format: :float },
  359. additional_cost: { type: :number, format: :float },
  360. document_price: { type: :number, format: :float },
  361. currency_id: { type: :string, format: :uuid },
  362. expiration_date: { type: :string, format: "date-time" },
  363. balance: { type: :number, format: :float },
  364. product_vendor_codes: {
  365. type: :array,
  366. items: {
  367. type: :object,
  368. required: [:vendor_code],
  369. properties: {
  370. vendor_code: { type: :string }
  371. }
  372. }
  373. },
  374. product_barcodes: {
  375. type: :array,
  376. items: {
  377. type: :object,
  378. required: [:barcode_type, :barcode],
  379. properties: {
  380. barcode_type: { type: :string },
  381. barcode: { type: :string }
  382. }
  383. }
  384. },
  385. product_packs: {
  386. type: :array,
  387. items: {
  388. type: :object,
  389. required: [:id, :name, :count],
  390. properties: {
  391. id: { type: :string, format: :uuid },
  392. name: { type: :string },
  393. count: { type: :integer }
  394. }
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. it "create relocation " do
  406. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  407. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  408.  
  409. # post "/v1/companies/#{@company.id}/shops/#{@shop.id}/relocations", headers: auth_headers
  410. # expect(response).to have_http_status(200)
  411. end
  412. end
  413.  
  414. response "code 453", "invoice object not found" do
  415. schema type: :object,
  416. required: [:errors],
  417. properties: {
  418. errors: {
  419. type: :array,
  420. items: {
  421. type: :object,
  422. required: [:id, :code, :title, :data],
  423. properties: {
  424. id: { type: :string },
  425. code: { type: :number },
  426. title: { type: :string },
  427. data: {
  428. type: :object,
  429. required: [:object_product_id],
  430. properties: {
  431. object_product_id: { type: :string, format: :uuid }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. }
  438.  
  439. it "returns code 453" do
  440. end
  441. end
  442.  
  443. response "code 454", "count couldn't be less than 1" do
  444. schema type: :object,
  445. required: [:errors],
  446. properties: {
  447. errors: {
  448. type: :array,
  449. items: {
  450. type: :object,
  451. required: [:id, :code, :title, :data],
  452. properties: {
  453. id: { type: :string },
  454. code: { type: :number },
  455. title: { type: :string },
  456. data: {
  457. type: :object,
  458. required: [:object_product_id],
  459. properties: {
  460. object_product_id: { type: :string, format: :uuid }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467.  
  468. it "returns code 454" do
  469. end
  470. end
  471.  
  472. response "code 455", "balance less than requested value" do
  473. schema type: :object,
  474. required: [:errors],
  475. properties: {
  476. errors: {
  477. type: :array,
  478. items: {
  479. type: :object,
  480. required: [:id, :code, :title, :data],
  481. properties: {
  482. id: { type: :string },
  483. code: { type: :number },
  484. title: { type: :string },
  485. data: {
  486. type: :object,
  487. required: [:invoice_number, :invoice_date, :object_product_id, :balance ],
  488. properties: {
  489. invoice_number: { type: :integer, format: :int32 },
  490. invoice_date: { type: :string, format: "date-time" },
  491. object_product_id: { type: :string, format: :uuid },
  492. balance: { type: :number, format: :float }
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499.  
  500. it "returns code 455" do
  501. end
  502. end
  503.  
  504. response "code 456", "variant not found" do
  505. schema type: :object,
  506. required: [:errors],
  507. properties: {
  508. errors: {
  509. type: :array,
  510. items: {
  511. type: :object,
  512. required: [:id, :code, :title, :data],
  513. properties: {
  514. id: { type: :string },
  515. code: { type: :number },
  516. title: { type: :string },
  517. data: {
  518. type: :object,
  519. required: [:variant_id ],
  520. properties: {
  521. variant_id: { type: :string, format: :uuid }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. }
  528.  
  529. it "returns code 456" do
  530. end
  531. end
  532.  
  533. response "code 457", "relocation couldn't be before shop created" do
  534. schema type: :object,
  535. required: [:errors],
  536. properties: {
  537. errors: {
  538. type: :array,
  539. items: {
  540. type: :object,
  541. required: [:id, :code, :title, :data],
  542. properties: {
  543. id: { type: :string },
  544. code: { type: :number },
  545. title: { type: :string },
  546. data: {
  547. type: :object
  548. }
  549. }
  550. }
  551. }
  552. }
  553.  
  554. it "returns code 457" do
  555. end
  556. end
  557.  
  558. response "code 458", "broduct-batch not unique" do
  559. schema type: :object,
  560. required: [:errors],
  561. properties: {
  562. errors: {
  563. type: :array,
  564. items: {
  565. type: :object,
  566. required: [:id, :code, :title, :data],
  567. properties: {
  568. id: { type: :string },
  569. code: { type: :number },
  570. title: { type: :string },
  571. data: {
  572. type: :object,
  573. required: [:variant_id, :object_product_id ],
  574. properties: {
  575. variant_id: { type: :string, format: :uuid },
  576. object_product_id: { type: :string, format: :uuid }
  577. }
  578. }
  579. }
  580. }
  581. }
  582. }
  583.  
  584. it "returns code 458" do
  585. end
  586. end
  587.  
  588. end
  589. end
  590.  
  591. ### SHOW ###
  592. path "/companies/{company_id}/shops/{shop_id}/relocations/{id}" do
  593. get "relocation info" do
  594. tags "Relocations"
  595. security [bearerAuth: {}]
  596. consumes "application/json"
  597.  
  598. parameter name: :company_id, in: :path, type: :string, format: :uuid
  599. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  600. parameter name: :id, in: :path, type: :string, format: :uuid
  601.  
  602. response "200", "relocation info" do
  603. schema type: :object,
  604. required: [:data],
  605. properties: {
  606. data: {
  607. type: :object,
  608. required: [:write_off, :meta],
  609. properties: {
  610. relocation: {
  611. type: :object,
  612. required: [:id, :number, :sender_stock_id, :sender_stock_name, :receiver_stock_id, :receiver_stock_name, :date, :user_id, :user_name, :status, :total_cost, :additional_cost, :total, :note, :relocation_products],
  613. properties: {
  614. id: { type: :string, format: :uuid },
  615. number: { type: :integer },
  616. sender_stock_id: { type: :string, format: :uuid },
  617. sender_stock_name: { type: :string },
  618. receiver_stock_id: { type: :string, format: :uuid },
  619. receiver_stock_name: { type: :string },
  620. date: { type: :string, format: "date-time" },
  621. user_id: { type: :string, format: :uuid },
  622. user_name: { type: :string },
  623. status: { type: :string },
  624. total_cost: { type: :number, format: :float },
  625. additional_cost: { type: :number, format: :float },
  626. total: { type: :number, format: :float },
  627. note: { type: :string },
  628. relocation_products: {
  629. type: :array,
  630. items: {
  631. type: :object,
  632. required: [:id, :variant_id, :product_id, :name, :sku, :unit_id, :category_id, :shop_tax_id, :product_pack_id, :count, :amount, :purchase_price, :additional_cost, :document_price, :currency_id, :expiration_date, :balance, :product_vendor_codes, :product_barcodes, :product_packs],
  633. properties: {
  634. id: { type: :string, format: :uuid },
  635. variant_id: { type: :string, format: :uuid },
  636. product_id: { type: :string, format: :uuid },
  637. name: { type: :string },
  638. sku: { type: :string },
  639. unit_id: { type: :string, format: :uuid },
  640. category_id: { type: :string, format: :uuid },
  641. shop_tax_id: { type: :string, format: :uuid },
  642. product_pack_id: { type: :string, format: :uuid },
  643. count: { type: :number, format: :float },
  644. amount: { type: :number, format: :float },
  645. purchase_price: { type: :number, format: :float },
  646. additional_cost: { type: :number, format: :float },
  647. document_price: { type: :number, format: :float },
  648. currency_id: { type: :string, format: :uuid },
  649. expiration_date: { type: :string, format: "date-time" },
  650. balance: { type: :number, format: :float },
  651. product_vendor_codes: {
  652. type: :array,
  653. items: {
  654. type: :object,
  655. required: [:vendor_code],
  656. properties: {
  657. vendor_code: { type: :string }
  658. }
  659. }
  660. },
  661. product_barcodes: {
  662. type: :array,
  663. items: {
  664. type: :object,
  665. required: [:barcode_type, :barcode],
  666. properties: {
  667. barcode_type: { type: :string },
  668. barcode: { type: :string }
  669. }
  670. }
  671. },
  672. product_packs: {
  673. type: :array,
  674. items: {
  675. type: :object,
  676. required: [:id, :name, :count],
  677. properties: {
  678. id: { type: :string, format: :uuid },
  679. name: { type: :string },
  680. count: { type: :integer }
  681. }
  682. }
  683. }
  684. }
  685. }
  686. }
  687. }
  688. },
  689. meta: {
  690. type: :object,
  691. required: [:mapping_id, :mapping_columns],
  692. properties: {
  693. mapping_id: { type: :string },
  694. mapping_columns: {
  695. type: :array,
  696. items: {
  697. type: :object,
  698. required: [:prop, :width, :visible],
  699. properties: {
  700. prop: { type: :string },
  701. width: { type: :number, format: :float },
  702. visible: { type: :boolean }
  703. }
  704. }
  705. }
  706. }
  707. }
  708. }
  709. }
  710. }
  711. it "relocation info" do
  712. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  713. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  714.  
  715. # get "/v1/companies/#{@company.id}/shops/#{@shop.id}/write_offs/#{@write_offf.id}", headers: auth_headers
  716. # expect(response).to have_http_status(200)
  717. end
  718. end
  719. end
  720. end
  721.  
  722. ### UPDATE ###
  723. path "/companies/{company_id}/shops/{shop_id}/relocations/{id}" do
  724. put "Update relocation " do
  725. tags "Relocations"
  726. security [bearerAuth: {}]
  727. consumes "application/json"
  728.  
  729. parameter name: :company_id, in: :path, type: :string, format: :uuid
  730. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  731. parameter name: :id, in: :path, type: :string, format: :uuid
  732. parameter name: :body, in: :body, schema: {
  733. type: :object,
  734. required: [:relocation],
  735. properties: {
  736. relocation: {
  737. type: :object,
  738. required: [:date, :note, :relocation_products],
  739. properties: {
  740. date: { type: :string, format: "date-time" },
  741. note: { type: :string },
  742. relocation_products: {
  743. type: :array,
  744. items: {
  745. type: :object,
  746. required: [:id, :variant_id, :object_product_id, :count, :additional_cost],
  747. properties: {
  748. id: { type: :string, format: :uuid },
  749. variant_id: { type: :string, format: :uuid },
  750. object_product_id: { type: :string, format: :uuid },
  751. product_pack_id: { type: :string, format: :uuid },
  752. count: { type: :number, format: :float },
  753. additional_cost: { type: :number, format: :float }
  754. }
  755. }
  756. }
  757. }
  758. }
  759. }
  760. }
  761.  
  762. response "201", "update relocation" do
  763. schema type: :object,
  764. required: [:data],
  765. properties: {
  766. data: {
  767. type: :object,
  768. required: [:relocation],
  769. properties: {
  770. relocation: {
  771. type: :object,
  772. required: [:id, :number, :sender_stock_id, :sender_stock_name, :receiver_stock_id, :receiver_stock_name, :date, :user_id, :user_name, :status, :total_cost, :additional_cost, :total, :note, :relocation_products],
  773. properties: {
  774. id: { type: :string, format: :uuid },
  775. number: { type: :integer },
  776. sender_stock_id: { type: :string, format: :uuid },
  777. sender_stock_name: { type: :string },
  778. receiver_stock_id: { type: :string, format: :uuid },
  779. receiver_stock_name: { type: :string },
  780. date: { type: :string, format: "date-time" },
  781. user_id: { type: :string, format: :uuid },
  782. user_name: { type: :string },
  783. status: { type: :string },
  784. total_cost: { type: :number, format: :float },
  785. additional_cost: { type: :number, format: :float },
  786. total: { type: :number, format: :float },
  787. note: { type: :string },
  788. relocation_products: {
  789. type: :array,
  790. items: {
  791. type: :object,
  792. required: [:id, :variant_id, :product_id, :name, :sku, :unit_id, :category_id, :shop_tax_id, :product_pack_id, :count, :amount, :purchase_price, :additional_cost, :document_price, :currency_id, :expiration_date, :balance, :product_vendor_codes, :product_barcodes, :product_packs],
  793. properties: {
  794. id: { type: :string, format: :uuid },
  795. variant_id: { type: :string, format: :uuid },
  796. product_id: { type: :string, format: :uuid },
  797. name: { type: :string },
  798. sku: { type: :string },
  799. unit_id: { type: :string, format: :uuid },
  800. category_id: { type: :string, format: :uuid },
  801. shop_tax_id: { type: :string, format: :uuid },
  802. product_pack_id: { type: :string, format: :uuid },
  803. count: { type: :number, format: :float },
  804. amount: { type: :number, format: :float },
  805. purchase_price: { type: :number, format: :float },
  806. additional_cost: { type: :number, format: :float },
  807. document_price: { type: :number, format: :float },
  808. currency_id: { type: :string, format: :uuid },
  809. expiration_date: { type: :string, format: "date-time" },
  810. balance: { type: :number, format: :float },
  811. product_vendor_codes: {
  812. type: :array,
  813. items: {
  814. type: :object,
  815. required: [:vendor_code],
  816. properties: {
  817. vendor_code: { type: :string }
  818. }
  819. }
  820. },
  821. product_barcodes: {
  822. type: :array,
  823. items: {
  824. type: :object,
  825. required: [:barcode_type, :barcode],
  826. properties: {
  827. barcode_type: { type: :string },
  828. barcode: { type: :string }
  829. }
  830. }
  831. },
  832. product_packs: {
  833. type: :array,
  834. items: {
  835. type: :object,
  836. required: [:id, :name, :count],
  837. properties: {
  838. id: { type: :string, format: :uuid },
  839. name: { type: :string },
  840. count: { type: :integer }
  841. }
  842. }
  843. }
  844. }
  845. }
  846. }
  847. }
  848. }
  849. }
  850. }
  851. }
  852. it "update relocation " do
  853. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  854. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  855.  
  856. # put "/v1/companies/#{@company.id}/shops/#{@shop.id}/relocations/#{@relocation.id}", headers: auth_headers
  857. # expect(response).to have_http_status(200)
  858. end
  859. end
  860.  
  861.  
  862. response "code 453", "invoice object not found" do
  863. schema type: :object,
  864. required: [:errors],
  865. properties: {
  866. errors: {
  867. type: :array,
  868. items: {
  869. type: :object,
  870. required: [:id, :code, :title, :data],
  871. properties: {
  872. id: { type: :string },
  873. code: { type: :number },
  874. title: { type: :string },
  875. data: {
  876. type: :object,
  877. required: [:object_product_id],
  878. properties: {
  879. object_product_id: { type: :string, format: :uuid }
  880. }
  881. }
  882. }
  883. }
  884. }
  885. }
  886.  
  887. it "returns code 453" do
  888. end
  889. end
  890.  
  891. response "code 454", "count couldn't be less than 1" do
  892. schema type: :object,
  893. required: [:errors],
  894. properties: {
  895. errors: {
  896. type: :array,
  897. items: {
  898. type: :object,
  899. required: [:id, :code, :title, :data],
  900. properties: {
  901. id: { type: :string },
  902. code: { type: :number },
  903. title: { type: :string },
  904. data: {
  905. type: :object,
  906. required: [:object_product_id],
  907. properties: {
  908. object_product_id: { type: :string, format: :uuid }
  909. }
  910. }
  911. }
  912. }
  913. }
  914. }
  915.  
  916. it "returns code 454" do
  917. end
  918. end
  919.  
  920. response "code 455", "balance less than requested value" do
  921. schema type: :object,
  922. required: [:errors],
  923. properties: {
  924. errors: {
  925. type: :array,
  926. items: {
  927. type: :object,
  928. required: [:id, :code, :title, :data],
  929. properties: {
  930. id: { type: :string },
  931. code: { type: :number },
  932. title: { type: :string },
  933. data: {
  934. type: :object,
  935. required: [:invoice_number, :invoice_date, :object_product_id, :balance ],
  936. properties: {
  937. invoice_number: { type: :integer, format: :int32 },
  938. invoice_date: { type: :string, format: "date-time" },
  939. object_product_id: { type: :string, format: :uuid },
  940. balance: { type: :number, format: :float }
  941. }
  942. }
  943. }
  944. }
  945. }
  946. }
  947.  
  948. it "returns code 455" do
  949. end
  950. end
  951.  
  952. response "code 456", "variant not found" do
  953. schema type: :object,
  954. required: [:errors],
  955. properties: {
  956. errors: {
  957. type: :array,
  958. items: {
  959. type: :object,
  960. required: [:id, :code, :title, :data],
  961. properties: {
  962. id: { type: :string },
  963. code: { type: :number },
  964. title: { type: :string },
  965. data: {
  966. type: :object,
  967. required: [:variant_id ],
  968. properties: {
  969. variant_id: { type: :string, format: :uuid }
  970. }
  971. }
  972. }
  973. }
  974. }
  975. }
  976.  
  977. it "returns code 456" do
  978. end
  979. end
  980.  
  981. response "code 457", "relocation couldn't be before shop created" do
  982. schema type: :object,
  983. required: [:errors],
  984. properties: {
  985. errors: {
  986. type: :array,
  987. items: {
  988. type: :object,
  989. required: [:id, :code, :title, :data],
  990. properties: {
  991. id: { type: :string },
  992. code: { type: :number },
  993. title: { type: :string },
  994. data: {
  995. type: :object
  996. }
  997. }
  998. }
  999. }
  1000. }
  1001.  
  1002. it "returns code 457" do
  1003. end
  1004. end
  1005.  
  1006. response "code 458", "broduct-batch not unique" do
  1007. schema type: :object,
  1008. required: [:errors],
  1009. properties: {
  1010. errors: {
  1011. type: :array,
  1012. items: {
  1013. type: :object,
  1014. required: [:id, :code, :title, :data],
  1015. properties: {
  1016. id: { type: :string },
  1017. code: { type: :number },
  1018. title: { type: :string },
  1019. data: {
  1020. type: :object,
  1021. required: [:variant_id, :object_product_id ],
  1022. properties: {
  1023. variant_id: { type: :string, format: :uuid },
  1024. object_product_id: { type: :string, format: :uuid }
  1025. }
  1026. }
  1027. }
  1028. }
  1029. }
  1030. }
  1031.  
  1032. it "returns code 458" do
  1033. end
  1034. end
  1035.  
  1036. response "code 459", "relocation object id not found" do
  1037. schema type: :object,
  1038. required: [:errors],
  1039. properties: {
  1040. errors: {
  1041. type: :array,
  1042. items: {
  1043. type: :object,
  1044. required: [:id, :code, :title, :data],
  1045. properties: {
  1046. id: { type: :string },
  1047. code: { type: :number },
  1048. title: { type: :string },
  1049. data: {
  1050. type: :object,
  1051. required: [:id],
  1052. properties: {
  1053. id: { type: :string, format: :uuid }
  1054. }
  1055. }
  1056. }
  1057. }
  1058. }
  1059. }
  1060.  
  1061. it "returns code 459" do
  1062. end
  1063. end
  1064.  
  1065.  
  1066. response "code 461", "can't delete relocation product balance is diferent from initial" do
  1067. schema type: :object,
  1068. required: [:errors],
  1069. properties: {
  1070. errors: {
  1071. type: :array,
  1072. items: {
  1073. type: :object,
  1074. required: [:id, :code, :title, :data],
  1075. properties: {
  1076. id: { type: :string },
  1077. code: { type: :number },
  1078. title: { type: :string },
  1079. data: {
  1080. type: :object,
  1081. required: [:balance, :count_in_units],
  1082. properties: {
  1083. balance: { type: :number, format: :float },
  1084. count_in_units: { type: :number, format: :float }
  1085. }
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091.  
  1092. it "returns code 461" do
  1093. end
  1094. end
  1095.  
  1096. response "code 463", "deleted relocation cannot be changed" do
  1097. schema type: :object,
  1098. required: [:errors],
  1099. properties: {
  1100. errors: {
  1101. type: :array,
  1102. items: {
  1103. type: :object,
  1104. required: [:id, :code, :title, :data],
  1105. properties: {
  1106. id: { type: :string },
  1107. code: { type: :number },
  1108. title: { type: :string },
  1109. data: {
  1110. type: :object
  1111. }
  1112. }
  1113. }
  1114. }
  1115. }
  1116.  
  1117. it "returns code 463" do
  1118. end
  1119. end
  1120.  
  1121. end
  1122. end
  1123.  
  1124. ### DESTROY ###
  1125. path "/companies/{company_id}/shops/{shop_id}/relocations/{id}" do
  1126. delete "delete relocation" do
  1127. tags "Relocations"
  1128. security [bearerAuth: {}]
  1129. consumes "application/json"
  1130.  
  1131. parameter name: :company_id, in: :path, type: :string, format: :uuid
  1132. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  1133. parameter name: :id, in: :path, type: :string, format: :uuid
  1134.  
  1135. response "204", "delete relocation" do
  1136.  
  1137. it "delete relocation" do
  1138. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  1139. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  1140.  
  1141. # delete "/v1/companies/#{@company.id}/shops/#{@shop.id}/relocations/#{@relocation.id}",
  1142. # headers: auth_headers
  1143. # expect(response).to have_http_status(204)
  1144. end
  1145. end
  1146.  
  1147. response "code 451", "can't delete relocation products moved by another relocation/write off" do
  1148. schema type: :object,
  1149. required: [:errors],
  1150. properties: {
  1151. errors: {
  1152. type: :array,
  1153. items: {
  1154. type: :object,
  1155. required: [:id, :code, :title, :data],
  1156. properties: {
  1157. id: { type: :string },
  1158. code: { type: :number },
  1159. title: { type: :string },
  1160. data: {
  1161. type: :object,
  1162. required: [:document_type, :document_id, :document_date, :document_number ],
  1163. properties: {
  1164. document_type: { type: :string },
  1165. document_id: { type: :string, format: :uuid },
  1166. document_date: { type: :string, format: "date-time" },
  1167. document_number: { type: :integer, format: :int32 }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. }
  1173. }
  1174.  
  1175. it "returns code 451" do
  1176. end
  1177. end
  1178.  
  1179.  
  1180. response "code 452", "can't delete relocation balance is different from initial" do
  1181. schema type: :object,
  1182. required: [:errors],
  1183. properties: {
  1184. errors: {
  1185. type: :array,
  1186. items: {
  1187. type: :object,
  1188. required: [:id, :code, :title, :data],
  1189. properties: {
  1190. id: { type: :string },
  1191. code: { type: :number },
  1192. title: { type: :string },
  1193. data: {
  1194. type: :object,
  1195. required: [:variant_id, :object_product_id, :balance, :unit_count ],
  1196. properties: {
  1197. variant_id: { type: :string, format: :uuid },
  1198. object_product_id: { type: :string, format: :uuid },
  1199. balance: { type: :number, format: :float },
  1200. unit_count: { type: :number, format: :float }
  1201. }
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }
  1207.  
  1208. it "returns code 452" do
  1209. end
  1210. end
  1211.  
  1212.  
  1213. end
  1214. end
  1215.  
  1216.  
  1217. ### EXPORT INDEX ###
  1218. path "/companies/{company_id}/shops/{shop_id}/relocations/export" do
  1219. get "export relocations" do
  1220. tags "Relocations"
  1221. security [bearerAuth: {}]
  1222. consumes "application/json"
  1223.  
  1224. parameter name: :company_id, in: :path, type: :string, format: :uuid
  1225. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  1226. parameter name: :status, in: :query, type: :string, enum: ["saved", "deleted"]
  1227. parameter name: :from_date, in: :query, type: :string, format: :date
  1228. parameter name: :to_date, in: :query, type: :string, format: :date
  1229. parameter name: :sender_stock_id, in: :query, type: :string, format: :uuid
  1230. parameter name: :receiver_stock_id, in: :query, typr: :string, format: :uuid
  1231. parameter name: :user_id, in: :query, type: :string, format: :uuid
  1232.  
  1233. response "200", "export relocations" do
  1234. schema type: :string, format: :binary
  1235.  
  1236. it "export relocations" do
  1237. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  1238. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  1239. end
  1240. end
  1241.  
  1242. end
  1243.  
  1244. end
  1245.  
  1246. ### EXPORT ###
  1247. path "/companies/{company_id}/shops/{shop_id}/relocations/{id}/export" do
  1248. get "export relocation" do
  1249. tags "Relocations"
  1250. security [bearerAuth: {}]
  1251. consumes "application/json"
  1252.  
  1253. parameter name: :company_id, in: :path, type: :string, format: :uuid
  1254. parameter name: :shop_id, in: :path, type: :string, format: :uuid
  1255. parameter name: :id, in: :path, type: :string, format: :uuid
  1256.  
  1257. response "200", "export relocation" do
  1258. schema type: :string, format: :binary
  1259.  
  1260. it "export relocation" do
  1261. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  1262. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  1263. end
  1264. end
  1265.  
  1266. end
  1267.  
  1268. end
  1269. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement